Edit: Nico Parodi's answer is correct. I will eventually return to finding out why, but for now I will just take it as it is and hope nothing else fails.
I have a table with three fields: "date", "name", "location". I want to group all the records selected from this table based on their date.
By copy-pasting some code from php mysql group by date with yyyy-mm-dd format, I've managed to get this array, date -> name:
$result = mysqli_query($con,"SELECT date, name, location FROM events");
while($row = mysqli_fetch_array($result)) {
$foo[$row['date']][]=$row['name'];
}
Everything's great, I can iterate it without issues. Now I want to store all the row columns as a value for the date key, so I try to store the entire row as a value:
$result = mysqli_query($con,"SELECT date, name, location FROM events");
while($row = mysqli_fetch_array($result)) {
$foo[$row['date']][]=$row;
}
And now I can't iterate it. count($rowCol) seems to give me the nr of columns in all the array for either keys, not just for one. How can I iterate it?
foreach($foo as $date => $events) {
echo $date . ": "; // this is okay
foreach($events as $key => $rowCol){
for ($i = 0; $i<count($rowCol); $i++) {
echo $rowCol[$i] . " ";
}
}
}