Possible Duplicate:
quick selection of a random row from a large table in mysql
Selecting random rows with MySQL
I am currently making a module to pull random business records from the mysql database and display the record as a ‘featured business’ inside the module. It all works fine, but im not 100% if this is the best way of doing it, as I hear its not overly fast ?. At present it is pretty rapid, and I should think the max amount of businesses I will get is approx 100-200, so is it ok to use the method below, or will things be a lot slower with that amount of records ?.
Many thanks 🙂
<?php
$result = mysql_query("SELECT * FROM `zgjzb_chronoforms_data_submitbusiness` ORDER BY RAND() LIMIT 0,4;");
$row = mysql_fetch_array($result);
echo $row['businessname'];
?>
You will be totally fine with that many records. Even if you are in the thousands you will be fine. Sql queries almost always impress me with their speed, and for queries with so few records, you’ll be fine.