Fetching a random row from MySQL and displaying it with PHP
im trying to select the row quote and author from my table and echo it
my goal is to create a random quote generator and display the actual quote and author.
I have entered 25 quotes in my table with 3 rows (ID, quote, author)
my code is the following and i keep getting the resource id #9 error
<?php mysql_select_db(name of database); $quotes = "SELECT author AND quote FROM inspirational_quotes ORDER BY RAND() LIMIT 1"; $result = mysql_query($quotes); WHILE ($row = mysql_fetch_array($result)): ENDWHILE; echo "$result"; ?>
First of all, I think you want
but I have an additional suggestion
Preload all the quote IDs
Now choose based on the id from quoteID table
This should scale just fine because the return value for @rnd_id comes from a list of ids with no gaps in the quoteID table.
Give it a Try !!!
You cant echo $result as a string
You are not echoing the right variable.
MySQL Select syntax
I suggest you to randomize results by PHP to improve performance. eg.: