Edit: Nico Parody's answer is correct. I will eventually return to asking why, but for now I will just take it as it is and hope that nothing else will succeed.
I have a table with three fields: "date", "name", "location". I want to group all the records selected from this table, depending on their date.
Having copied the following code from php mysql group by date in the format yyyy-mm-dd , I 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 is fine, I can repeat it without any problems. Now I want to save all row columns as a value for the date key, so I'm trying to save 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 repeat it. count ($ rowCol) seems to give me nr columns in the entire array for any keys, not just one. How can I repeat 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] . " "; } } }
source share