ここで私が間違っていることを教えてください。シンプルなものだとおもいます。
データセットを取得する SQL クエリ:
SELECT * FROM articles WHERE category='category' ORDER BY publish_date DESC, id DESC LIMIT 0, 10
私が到達しようとしている多次元配列:
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..
私は数時間、次のphp関数をいじっています:
$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);