Random Records Query in MySQL
<?php include('connection.php');
$num="SELECT *, rand() FROM news ORDER BY rand() LIMIT 5;";
$row=mysql_query($num);
$news=mysql_fetch_array($row);
?>
How this Code Work:
- The above Query in $num variable will select all record from the table “news” that are Random .
- They are five in number because the “LIMIT 5” is applied.
- Rand() function select random record from the database
- When you will refresh the page or when a page is open it select other random record
- Five new records will be show on every time.