0

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{

[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 エコーを作成するときに、特定の投稿に関連するコメントをループアウトできるようにするためです。

たとえば、comment[0][1] は「$postidarray の最初のキーからのコメント 2」をエコーし​​ます。

どんな助けでも大歓迎です。

4

1 に答える 1