admin管理员组

文章数量:1125966

I'm working on creating a comment system for an event plugin I am creating. I have the commenting and replies forms working correctly, I just need help with writing them out to the site. I am on MySql 5.6 so can't use a recursive query.

Comment Table

id - int
eventid - int
userid - int
content - text
datesaved - datetime
parentid - int

PHP/SQL What I currently have to display the comments. This doesn't display the replies, that's what I need help with.

$commentsql = $wpdb->get_results("SELECT comm.id as id, comm.eventid as eventid, comm.userid as userid, comm.content as comment, comm.datesaved as date, users.meta_value as fname, users2.meta_value as lname
                                FROM " . $wpdb->prefix . "cmc_communitybb_event_comments as comm
                                inner join " . $wpdb->prefix . "usermeta as users on comm.userid = users.user_id and users.meta_key = 'first_name'
                                inner join " . $wpdb->prefix . "usermeta as users2 on comm.userid = users2.user_id and users2.meta_key = 'last_name'
                                where comm.eventid=$eventid and comm.parentid is null order by comm.datesaved desc");

foreach ($commentsql as $comment) {
    //code to display comments goes here
}

本文标签: