php - How to display 3 random values from MYSQL table -
how go displaying 3 random values each time page loaded? @ minute have displaying 1 @ time using following code:
<?php $ssqlquery = "select careername careers order rand() limit 1"; $aresult = mysql_query($ssqlquery); $arow = mysql_fetch_array($aresult, mysql_assoc); $squoteoftheday = $arow['careername']; echo $squoteoftheday; ?>
i have tried doing limit 5 had no effect on result. thanks
you'll have call mysql_fetch_assoc()
again every single record fetching.
so, use limit 3
, loop through result set. this:
$ssqlquery = "select careername careers order rand() limit 3"; $aresult = mysql_query($ssqlquery); while($arow = mysql_fetch_array($aresult, mysql_assoc)) { $squoteoftheday = $arow['careername']; echo $squoteoftheday; }
refer manual page of mysql_fetch_assoc()
. you'll find more examples there.
Comments
Post a Comment