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
Share on other sites

$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.

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.