Jump to content

[SOLVED] Saving array output in variable?


xxtobirichter

Recommended Posts

Hello, i am experimenting with the following.

 

$answerpick = mysql_query("SELECT id FROM answer order by rand() limit 1");

 

Receive array from mysql.

Now i would like to store the value in a variable to work with it throughout the script, is that possible?

I ve tried to

{

print "The answer is".$test{'id'}." <br>";

} and it prints the id...so far so good, but now i would like to perform the following

 

$choicepick= mysql_query("SELECT cid FROM choice where cid<>$id");

$id should refer to the id retrieved in the first querry. I tried to define $id = ".test$('id')." but that appears to be impossible, I ve tried to find info on the net but couldnt.

If this approach doesnt work is there another way to store array information in a variable or to execute the $choicepick querry with regard to retrieved information from $answerpick?

 

Thanks for any input

Regards

Tobi

 

Link to comment
https://forums.phpfreaks.com/topic/81937-solved-saving-array-output-in-variable/
Share on other sites

$choicepick= mysql_query("SELECT cid FROM choice where cid<>'{$test['id']}'");

 

$choicepick= mysql_query("SELECT cid FROM choice where cid!='{$test['id']}'");

 

 

Im not sure if <> is a valid mysql operator, so my second one I know is where I use != but give that a try.

$id = $test['id'];

$choicepick= mysql_query("SELECT cid FROM choice where cid<>'{$id}'"); //should work fine

 

Also, <> is like saying is less than or greater than....  So, the numbers less than 1 and greater than one would be all numbers that are not one, so it's like saying not equal to 1.

 

<> is valid in SQL (MySQL/MSSQL I know for sure), PHP, and I think some of the lower level languages might even use it, but I'm not sure.

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.