Jump to content

random specific entry from database


Ramtree

Recommended Posts

i need to random an entry where question_answered = $_POST['randompick'] (the form).

$r_pick = $_POST['randompick'];

$randomvar = "mysql_query(SELECT * FROM quiz_correct_response WHERE question_answered = $r_pick ORDER BY rand() LIMIT 1)";
  while($pick = mysql_fetch_array($randomvar))
  {
  echo $pick[0];
  }

 

but somehow it's giving me error

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

 

please help me if you can, thanks

Link to comment
https://forums.phpfreaks.com/topic/166173-random-specific-entry-from-database/
Share on other sites

$randomvar = "mysql_query(SELECT * FROM quiz_correct_response WHERE question_answered = $r_pick ORDER BY rand() LIMIT 1)";

 

should be:

$randomvar = mysql_query("SELECT * FROM quiz_correct_response WHERE question_answered = $r_pick ORDER BY rand() LIMIT 1");

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.