Could some fresh eyes please tell me what I’m doing wrong here? I’m sure it’s something simple.
The sql query that retrieves the data set:
SELECT * FROM articles WHERE category='category' ORDER BY publish_date DESC, id DESC LIMIT 0, 10
The multidimensional array that I am trying to reach:
list [
publish_date [
0 [ id, title, body ]
1 [ id, title, body ]
2 [ id, title, body ]]
publish_date [
0 [ id, title, body ]
1 [ id, title, body ]]
publish_date [
0 [ id, title, body ]
1 [ id, title, body ]
2 [ id, title, body ]
3 [ id, title, body ]]]
Etc..
I have been fiddling with the following php function for a few hours now:
$result = $sql->prepareQuery($query_string);
// iterate through array and place results in an array at row index
$list = ['group_date' => ' '];
$r = 0;
while ($rows = mysql_fetch_assoc($result)) {
if ($list['publish_date'] != $rows['pub_date']) {
$list['publish_date'] = $rows['pub_date'];
$r = 0;
foreach ($rows as $key => $val) {
$list['publish_date'][$r[$key = $val]];
}
$r++;
}
else {
foreach ($rows as $key => $val) {
$list['publish_date'][$r[$key = $val]];
}
$r++;
}
}
// return result
print_r($list);
Think you are making things to complicated: