Re: Pulling a random image
| From: | Sander Roobol | Date: | Mon, 03 Sep 2001 16:30:06 +0000 |
| Subject: | Re: Pulling a random image | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-64976@lists.php.net to get a copy of this message | ||
Please ask support questions on the PHP-GENERAL mailinglist.
----- Original Message -----
From: Brad R. C.
To: php-dev@lists.php.net
Sent: Monday, September 03, 2001 5:00 PM
Subject: [PHP-DEV] Pulling a random image
Hello everyone... I have been working on this random function for awhile now.. and it is close to
being complete. It works as for a random function. But what my goal was is to make it where it goes
through all the images before showing a random twice. Kind of like you put all the images in a
bucket, and random select one out of the bucket while you eyes are closed, once you take it out of
the bucket you put it on the table till there is no images left in the bucket, then you fill the
bucket again and start over.
Now... I thought the following function did that, but for some reason it is not... I might have
just missed a line of code, or misspelled something, but I come to you guys/gals to be more second
pair of fresh eyes to see if you can find where I made a mistake.
Thanks..
-------------code snippet--------------------
function getRandomUser()
{
static $itemarray;
if (empty($itemarray)) {
$connection = mysql_pconnect(SQL_SERVER, SQL_UID, SQL_PWD);
mysql_select_db(SQL_DB, $connection);
$sql = "select * from user where valid = 1 and inrotation = 1";
$query = mysql_query($sql);
while($thisrow = mysql_fetch_array($query)) {
$itemarray[] = $thisrow;
}
}
if (sizeof($itemarray) == 0)
return Array('userid'=>'-1', "photo_name"=>'',
"photo_num"=>'', "counter"=>'',
"size"=>'');
srand((double)microtime()*1000000);
$row = rand(0, sizeof($itemarray)- 1);
$toreturn = $itemarray[$row];
$itemarray = array_splice($itemarray,$row,1);
return $toreturn;
}
-------------code snippet--------------------
thanks guys... :)
Brad C