where is $impressions coming from?
My suggestion is along with the advertisers information (email, id, login, pass, etc.) I would have the path to image, and number of impressions left in a database.
Then I would do something like this..
<?php
$query = "SELECT id,path, impressions FROM `adverts` WHERE impressions > 0";
$results = mysql_query($query) or die(mysql_error());
//This will return all rows in the database where the number of impressions left is more than none.
$i = 0;
while($row = mysql_fetch_assoc($results))
{
$array[$i]['id'] = $row['id'];
$array[$i]['path'] = $row['path'];
$array[$i]['impressions'] = $row['impressions'];
// here we've entered all the data into an array we can use outside of the loop.
}
mt_srand(microtime()); //initiate the random number generator with a unique seed
$rand = mt_rand(0, count($array)-1); // get a random number from 0 to max array
$path = $array[$rand]['path'];
echo $path; //to whatever you need to do.
// Changing value of impressions.
$imp = $array[$rand]['impressions'];
$imp--;
$id = $array[$rand]['id'];
//Update the database to reflect decrement of impressions.
$updateQuery = "UPDATE `adverts` SET impressions=$imp WHERE id=$id";
$runquery = mysql_query($updateQuery) or die(mysql_error());
?>
I dont guaranty the accuracy of the code above, I'm at work and can't test it. But the general idea should help you 🙂
[edit]
If you don't have a database however, the above might be kind of useless. though, you could use flat files to accomplish prettymuch the same thing.
[/edit]