【发布时间】:2013-04-17 18:06:04
【问题描述】:
我在 MYSQL 中有以下表格:
CommentTable 包含以下列:comment、commenter、datecommented 和 postid 带有列的 PostTable:postid、dateposted
我在 php 中执行这个查询
Select commentTable.comment, commentTable.commenter, commentTable.datecommented, shareTable.postid, shareTable.dateshared from shareTable Left Join commentTable on commentTable.postid = shareTable.postid where shareTable.postid IN ($postidarray) order by shareTable.dateshared desc
其中 $postid 数组是一个帖子 ID 数组。
我遇到的问题是当我尝试将查询结果排序为多维数组时。
我想要一个名为 comment 的多维数组,它会这样
Comment{
[0] {
[0] => "Comment 1 from first key in $postidaray"
[1] => "Comment 2 from first key in $postidarray"
}
[1] {
[0] => "Comment 1 from second key in $postidarray"
} // assuming there is only one comment for the second key in $postidarray
[2]{
[0] => "Comment 1 from third key in $postidarray"
[1] => "Comment 2 from third key in $postidarray"
[2] => "Comment 3 from third key in $postidarray"
[3] => "Comment 4 from third key in $postidarray"
}
// assuming there are 4 comments for the third key in $postidarray
}
}
我这样做是为了在进行 php echo 时可以循环出与特定帖子相关的 cmets
例如,comment[0][1] 会回显“来自 $postidarray 中第一个键的评论 2”
感谢任何帮助。
【问题讨论】:
-
获取不到多维数组。在您的语句中使用 GROUP 并从结果集中创建(如果真的需要)您的数组。
-
对不起我没有关注
-
可以得到一个多维数组。请看下面的解决方案。
标签: php mysql multidimensional-array