Click to See Complete Forum and Search --> : Display only 5 or 10 from mysql_query($result)


itbeings
06-28-2006, 04:16 PM
I want to display only 5 or 10 from my SELECT * FROM table_name; query.
If the query selects all from the table_name, I want it to randomly pick any 5 or 10. and when the page is refreshed it will run again and display different values, selecting randonly.
How can I go about this in php?

GaryS
06-28-2006, 05:07 PM
Here's a way to do it in your query

SELECT * FROM table_name ORDER BY RAND() LIMIT 10;

(Think this is quite slow, so not recommended for large tables.)

XeroSiS
06-29-2006, 06:29 AM
what would be recommended for a large table?

aussie girl
06-29-2006, 08:22 AM
There's also no guarantee that some of the results aren't going to be the same as the ones before, you need to include a DISTINCT on one your column names, that may also make it quicker

GaryS
06-29-2006, 09:25 AM
what would be recommended for a large table?


This (http://www.greggdev.com/web/articles.php?id=6) is worth a read.