Re: adding to an array variable using a loop...?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I assume the field 'date' in your database is a date field, and in your code
you are trying to do a date + 1, but you are not specifying *what* you are
adding to the date (ie. 1 day, 1 week, 1 month), therefore the whole
variable is being replaced (with a 1). Try looking at the various date
functions (or string functions) to work out how to do this. Depending on how
your date is setup you would use strtotime() or mktime() (or both).

Adam

--- Original 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 ;
  }

 }


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux