note 16162 deleted from function.rand by jimw
| From: | jimw@php.net | Date: | Tue, 18 Dec 2001 19:31:02 +0000 |
| Subject: | note 16162 deleted from function.rand by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-23150@lists.php.net to get a copy of this message | ||
# Simple and faster (I think) - but not 100% correct -
# code to get a random row from a table with mysql < 3.23
# (in 3.23 you can use SELECT * FROM $table ORDER BY RAND() )
srand((double)microtime()*1000000 );
$arrRes = mysql_query("SELECT intId FROM tblBild ORDER BY intId DESC LIMIT 1");
$intMax = mysql_result($arrRes,0);
$intMax = rand(0,$intMax);
$query = "SELECT intFilmNr,strFileName FROM tblBild WHERE intId >= '$intMax' LIMIT
1";
list($intNr,$strName) = mysql_fetch_array( mysql_query($query) );
$src = "film/preview/$intNr/$strName";
$strImage = "<IMG SRC='$src' align=right>";
# NOTE! If you have 1,2,3,4,200 as intId,
# The row 200 will more often be the chosen one.