Jump to content

setting a variable equal to the result of a mysql select statement


phpchick

Recommended Posts

When I run

 

'select 1700-price as blah from goldclose as t2 order by dayid desc limit 1'

 

by itself in mysql I get a numerical result: one row, one column.

 

In my php script, the 1700 is actually a variable. so here it is

 

$changequery = sprintf("select $goldprice-price as change from goldclose order by dayid desc limit 1");

$change = mysql_query(changequery);

while ($row = mysql_fetch_array($change)) {

    printf("$row[0]"); 

}

 

mysql_free_result($changeresult);

 

 

I get the following error,

 

Warning:  mysql_fetch_array(): supplied argument is not a valid MySQL result resource in <b>/root/fuzzy/htmlmain4.php on line 99

 

Warning:  mysql_free_result(): supplied argument is not a valid MySQL result resource in <b>/root/fuzzy/htmlmain4.php on line 103

 

Not sure why? All i want is to get the result of that select statement into a variable such as $change

Link to comment
Share on other sites

i fixed it with this

 

 

 

$changequery = sprintf("select $goldprice-price as change1 from goldclose order by dayid desc limit 1");

$changeget = mysql_query($changequery);

$changearray = mysql_fetch_array($changeget);

printf("$changearray[0]"); 

 

 

the problem was change can't be used as the name of a column. :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.