Sometimes we may need to display some value selected from database table which is having many records. In this situation we can select them randomly to improve user experience. It applies to displaying random advertisements, testimonials, quotes,images,background colors and news.
php is having a function rand() for getting random number within a range. Syntax is shown below.
int rand ( int $min , int $max )
Sample code is shown below.
We can use RAND() function of MySQL also to achieve this.
For example below code will select 10 random rows from the mysql table.