MySQL random display record
Hey-ho! This website has been great!!
I have a mysql Q --
I have a databse w/two tables.. 'generalinfo' and 'serviceareas'.. All I simply would like to do is create a display to randomly display a record. I assume I can pull from the ID number (housed in generalinfo)
I've tried:
$query=SELECT 'generalinfo'* FROM id ORDER BY RAND() LIMIT 1)";
What am I doing wrong?!
Any help would be appreciated!
I have a mysql Q --
I have a databse w/two tables.. 'generalinfo' and 'serviceareas'.. All I simply would like to do is create a display to randomly display a record. I assume I can pull from the ID number (housed in generalinfo)
I've tried:
$query=SELECT 'generalinfo'* FROM id ORDER BY RAND() LIMIT 1)";
What am I doing wrong?!
Any help would be appreciated!
0
Comments
You have a syntax mystake, the "FROM" always refers to a table, not a column.
$query=SELECT 'generalinfo'.* FROM generalinfo ORDER BY RAND() LIMIT 1)";
also try to output errors or use myphpadmin to test your queries...
Im no expert at mysql, either -- but im trying
$query=SELECT 'generalinfo'.* FROM generalinfo ORDER BY RAND() LIMIT 1)";
but nothing is coming up.. I don't need a WHERE tag, in this case?
What would the easiest way to pull 1 random ID out of this batch?
$query = "SELECT id FROM generalinfo ORDER BY RAND() LIMIT 1";
[/php]
Try that.
I goofed and copied over the ')' at the end
$query= "SELECT 'generalinfo'.* FROM generalinfo ORDER BY RAND() LIMIT 1"
and
$query = "SELECT id FROM generalinfo ORDER BY RAND() LIMIT 1"
both should work, except the top one will return all values in the row, while the bottom one will return just the id
Thank Ya!