-2

特定のコメントに関連付けることができる返信を持つコメント システムを構築しようとしています。

これが私のサンプルコードです。2 つのテーブルを結合して、異なるコメントに対する各返信を表示しようとしました。

function get_comments() {
    $query = $this->link->query("SELECT * FROM comments, reply");

    $rowCount = $query->rowCount();

    if ($rowCount >= 1) {
        $result = $query->fetchAll();
    }
    else {
        $result = 0;
    }

    return $result;
}
4

2 に答える 2

1

その SQL クエリは、何かを結合しているようには見えません。

返信もコメントなので、次のようなテーブル構造にすることができます。

table comments
    id
    in_reply_to_id
    commenter_name
    comment_text

は、このコメントが返信するコメントのin_reply_to_idを指します。id

次に、次のようにクエリできます。

select * from comments where in_reply_to_id = whatever_comment_id

idに等しいコメントへのすべての返信を取得しますwhatever_comment_id

于 2013-10-11T20:27:26.140 に答える