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

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. :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.