I have used the below link to create an array of date.
http://boonedocks.net/mike/archives/137-Creating-a-Date-Range-Array-with-PHP.html
However, I wanted to replace dates in that array by comparing the date(in the array) and the date(in query result).
If they are equal then I will replace that date in the array with the result in the mysql query.
array:
array(
9/1/2013,
9/2/2013,
9/3/2013,
9/4/2013,
9/5/2013
)
query result:
| date | value0 | value1 | value2 | and so on...
| 9/2/2013 | 5 | A | AQ |
| 9/3/2013 | 6 | V | CD |
| 9/5/2013 | 7 | X | SA |
the result must be like this:
PHP date ----> 9/1/2013 0
Database ----> 9/2/2013 5
Database ----> 9/3/2013 6
PHP date ----> 9/4/2013 0
Database ----> 9/5/2013 7
How do i do that in PHP? I've been experimenting with while loops inside foreach, but does not work.
What if i have several columns in my table? I've tried the answers below but i think it is just two dimensional? see above edit in my mysql query.
Edit:
I have done this now:
<?php
$getDays = array(
9/1/2013,
9/2/2013,
9/3/2013,
9/4/2013,
9/5/2013
);
$result = array();
while($row = mysql_fetch_assoc($getTime))
{
$result[] = $row;
}
for($i=0; $i < count($getDays); $i++)
{
?>
<tr>
<td><?php echo $result[$i]['date']; ?></td>
<td><?php echo $result[$i]['value0']; ?></td>
<td><?php echo $result[$i]['value1']; ?></td>
<td><?php echo $result[$i]['value2']; ?></td>
</tr>
<?php
}
?>
But the problem is: some dates are not being outputted just like i wanted it to be in order.