请一些新鲜的眼睛告诉我我在这里做错了什么?我确定这很简单。
检索数据集的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);