PHP Comment Reply Solution

Source: Internet
Author: User
PHP Comment reply
This post was last edited by haoren026 on 2013-12-15 21:12:03

I know the problem is very, very elementary. I also searched a lot of posts, but it was quite troublesome, or I was not able to achieve enough.

The problem is this:
I am practicing blogging system, to implement the comment reply function, the request is not high, the guest comments, bloggers reply to comments, can not reply again, only a layer of relationship: Comment-reply. It's so simple.

The data table structure of the methods on the Internet is mostly as follows:
ID: Comment ID
PID: Comment ID of the reply
Content: Comments

I want to know how to find a record of a reply when there are several lines between the record of the comment and the record of the reply, such as:

ID PID
1 0
2 0
3 1//replies and comments are separated by several lines
4 0

This problem is very difficult to solve in the SQL sort reorganization. Help the Great God, thank you very much

share to: more


------Solution--------------------
Fixed level two stories
Http://sqlfiddle.com/#!2/e433e/1
This statement is learned with MySQL moderators

SELECT * from ' comment ' ORDER by if (PID=0,ID,PID) ASC

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.