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.
$sqlbanner="select * from table_name
$recbanner=mysql_query($sqlbanner);
$rows=mysql_num_rows($recbanner);
$rand=rand(0,$rows-1);
$page_text=mysql_result($recbanner,$rand,'page_text');
We can use RAND() function of MySQL also to achieve this.
For example below code will select 10 random rows from the mysql table.
SELECT * FROM <table name> where <condition> ORDER BY RAND() LIMIT 10
More Articles...
No comments:
Post a Comment