Page 1 of 1

creating multidimensional arrays using foreach

Posted: Tue Oct 21, 2008 2:50 am
by deejay
This should be fairly simple but I just don't seem to able to tweek it to work. What I need to do is to store a true or false result a dimesion deeper that the date .
so it'll probably be the code -> $date[result] = TRUE;
be doing wrong. have also tried $date->result = TRUE;

Code: Select all

 
 function double_bookings($dates, $rid){   // will need an array of  dates and the rid of the property   // what we want is to return a value next to the datte
 
   foreach ($dates as $key => $date ){
 
   echo $date.'<BR>';
     $query = "SELECT * FROM bookings WHERE rid = $rid AND arrival_date <= '$date' AND departure_date >= '$date' ";
     $result = mysql_query($query);
      $row_count = mysql_num_rows($result);
       echo $row_count.'<BR>';
      if($row_count == 1){
        $date[result] = TRUE;
      }  else {
        $date[result] = FALSE;
      }
   }
   return  $dates;
 }
 
 
// and to call it up 
 
$date_array = list_dates_between_dates('2008-10-24', '2008-10-30');
 
print_r($date_array);
 echo '<BR><BR>';
 $date_results = double_bookings($date_array, '73');
 
 var_dump($date_results);
  echo '<BR><BR>';
/*  $c = 0; */
foreach ($date_results as $date){
 
 echo "The $date returns a ";
 if  ($date[result] == TRUE){
    echo 'Positive result.<BR>';
 } else {
    echo 'Negative result.<BR>';
 }
 

the result of this is in testing a particular date and rid is
Array ( [0] => 2008-10-24 [1] => 2008-10-25 [2] => 2008-10-26 [3] => 2008-10-27 [4] => 2008-10-28 [5] => 2008-10-29 [6] => 2008-10-30 )

2008-10-24
0
2008-10-25
0
2008-10-26
0
2008-10-27
0
2008-10-28
0
2008-10-29
1
2008-10-30
1
array(7) { [0]=> string(10) "2008-10-24" [1]=> string(10) "2008-10-25" [2]=> string(10) "2008-10-26" [3]=> string(10) "2008-10-27" [4]=> string(10) "2008-10-28" [5]=> string(10) "2008-10-29" [6]=> string(10) "2008-10-30" }

The 2008-10-24 returns a Negative result.
The 2008-10-25 returns a Negative result.
The 2008-10-26 returns a Negative result.
The 2008-10-27 returns a Negative result.
The 2008-10-28 returns a Negative result.
The 2008-10-29 returns a Negative result.
The 2008-10-30 returns a Negative result.
Thanks for any help or guidance anyone can give.