adding to an array variable using a loop...?
| From: | David Rice | Date: | Mon, 10 Mar 2003 19:02:47 +0000 |
| Subject: | adding to an array variable using a loop...? | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-26239@lists.php.net to get a copy of this message | ||
I want to create an array from results returned from a mysql query. I want it to go through each row in the returned result, and if the variable in the array staff exists add 1 to the total, if it doesnt exist, set it as one and carry on.
But when i run this and do var_dump, it just returns "1" in the array for every date.
I don't think my logic for this is correct, please help.
Cheers,
Dave.
==========
$query = "SELECT * FROM Rota WHERE date >= $start and date <= ($start + INTERVAL 6 DAY) ";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)){
$x = 1;
$date = $row['Date'];
if ( isset($staff[$date] ) ){
$staff[$date] = $staff[$date] + $x ;
}
else{
$staff[$date] = $x ;
}
}
_________________________________________________________________
It's fast, it's easy and it's free. Get MSN Messenger today! http://messenger.msn.co.uk