Selecting random row from mysql

S

Selecting a random row from mysql the easy way

$query = "select * from tableName order by rand() limit 1";
$resultSet = mysql_query($query);
$randomRow = mysql_fetch_row($result_set);

Selecting multiple random rows is as easy as changing the limit, say i
wanted 10 random rows, the code would look like this:

$query = "select * from tableName order by rand() limit 10";
$resultSet = mysql_query($query);
$randomRow = mysql_fetch_row($result_set);

About the author

Talifhani Luvhengo

A collection of particles named Tali Luvhengo

Add comment

Categories

Page optimized by WP Minify WordPress Plugin