arrray loop values

Here I access ‘date’ key values from rows of DB table. And I can echo these values, no problem.

[php] $res = $mysqli->query(“SELECT * FROM alfred ORDER BY id ASC”);
$row = $res->fetch_all(MYSQLI_ASSOC);

foreach ($row as $key => $value){
	$availDate = $value['date'];
	echo $availDate.'<br />';
}[/php]

This loop above shows all ‘date’ values from DB, in this case there are 3 dates- [tt]“2012-09-25”[/tt] [tt]“2012-09-27”[/tt] and [tt]“2012-09-29”[/tt].
But then I need to compare each of these ‘date’ values against values of [tt]$date->format(‘Y-m-d’)[/tt] from the code below and display each date with corresponding “busy” or “available” status into separate

of the table. My following version compares only the “last” value of ‘date’ key - [tt]“2012-09-29”[/tt], but I need to compare each ‘date’ value from the array above, it means also [tt]“2012-09-25”[/tt] and [tt]“2012-09-27”[/tt]. I have tried many versions but still unsuccessful. Any ideas?

[php] $date = new DateTime();
$endDate = new DateTime(’+10 day’);
for($date->format(‘Y-m-d’); $date->format(‘Y-m-d’) < $endDate->format(‘Y-m-d’); $date->modify(’+1 day’)){
if ($date->format(‘Y-m-d’) == $availDate){
echo ‘

’.$date->format(‘Y-m-d/D’).’ busy’;
} else {
echo ‘’.$date->format(‘Y-m-d/D’).’ available’;
}
}[/php]

The result I am getting now is table row that shows all the dates within the range as expected but “busy” status is showed only to the date of “2012-09-29” which is the last ‘date’ value of my $row array.
But in fact I need to show “busy” status also into

of [tt]“2012-09-25”[/tt] and of [tt]“2012-09-27”[/tt] as these also are ‘date’ values that are existing in $row array and matches the dates range of my ‘for’ loop.

with the help of the code:
[php]$aAvailDate = array();
foreach ($row as $key => $value){
$aAvailDate[] = $value[‘date’];
}
$date = new DateTime();
$endDate = new DateTime(’+10 day’);
for($date->format(‘Y-m-d’); $date->format(‘Y-m-d’) < $endDate->format(‘Y-m-d’); $date->modify(’+1 day’)){
if (in_array($date->format(‘Y-m-d’), $aAvailDate)){
echo ‘

’.$date->format(‘Y-m-d/D’).’ busy’;
} else {
echo ‘’.$date->format(‘Y-m-d/D’).’ available’;
}
} [/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service