MySQL random display record

edited March 2005 in Internet & Media
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!

Comments

  • ButtersButters CA Icrontian
    edited March 2005
    $query=SELECT 'generalinfo'* FROM id ORDER BY RAND() LIMIT 1)";

    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...
  • edited March 2005
    thanks, but still no luck!?

    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?
  • a2jfreaka2jfreak Houston, TX Member
    edited March 2005
    [php]
    $query = "SELECT id FROM generalinfo ORDER BY RAND() LIMIT 1";
    [/php]

    Try that.
  • ButtersButters CA Icrontian
    edited March 2005
    mpearson55 wrote:
    thanks, but still no luck!?

    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?


    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
  • edited March 2005
    Awesome! We're lookin' good now!

    Thank Ya!
Sign In or Register to comment.