order by rand() limit 3; 亂數取出三筆資料

討論區:

order by rand() limit 3; 亂數取出三筆資料

使用範例:

$str = "select * from table where 1 order by rand() limit 3";
$res = mysql_query($str);

$coun = mysql_num_rows($res); //得到資料總全筆數

while($a = @mysql_fetch_array($res))
{
echo $a['sn'];
........
}