Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7864401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:46:44+00:00 2026-06-02T23:46:44+00:00

$rget_comments = mysql_query(SELECT DISTINCT comment.id, comment.comment_name, comment.comment_body FROM rs_comments AS comment WHERE comment.comment_parent =’0′

  • 0
$rget_comments  = mysql_query("SELECT DISTINCT comment.id, comment.comment_name, comment.comment_body FROM rs_comments AS comment WHERE comment.comment_parent ='0' ORDER BY comment.id ASC");
while( $get_comment = mysql_fetch_array( $rget_comments ) )
{

    echo '+ <a href="comment.php?id=' . $get_comment['id'] . '">' . $get_comment['comment_name'] . '</a><br />';
    echo $get_comment['body'] . '<br />';

    $rget_comments  = mysql_query("SELECT DISTINCT 
    (sub_comment.id) AS sub_id, (sub_comment.comment_name) AS sub_comment_name, (sub_comment.comment_body) AS sub_comment_body 
    FROM rs_comments AS sub_comment WHERE sub_comment ON sub_comment.comment_parent = '1'");
    while( $get_comment = mysql_fetch_array( $rget_comments ) )
    {

        echo '- <a href="comment.php?id=' . $get_comment['sub_id'] . '">' . $get_comment['sub_comment_name'] . '</a><br />';
        echo $get_comment['sub_body'] . '<br />';
    }

}

My table info:

CREATE TABLE IF NOT EXISTS `rs_comments` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `comment_type` varchar(255) NOT NULL,
  `comment_post_ID` int(11) NOT NULL,
  `comment_parent` int(11) NOT NULL,
  `comment_name` varchar(128) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  `comment_body` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;

INSERT INTO `rs_comments` (`id`, `comment_type`, `comment_post_ID`, `comment_parent`, `comment_name`,`comment_body`) VALUES
(1, 'post', 1, 0, 'test comment', 'test comment body'),
(2, 'post', 1, 0, 'test comment 2', 'test comment 2 body'),
(3, 'post', 1, 1, 'sub comment 1', 'sub comment 1 body'),
(4, 'post', 1, 1, 'sub comment 2', 'sub comment 2 body');

I got a query, but will only return the first row:

  $rget_comments    = mysql_query("
    SELECT DISTINCT 
    comment.id, comment.comment_name, comment.comment_body, (sub_comment.id) AS sub_id, (sub_comment.comment_name) AS sub_comment_name, (sub_comment.comment_body) AS sub_comment_body
    FROM rs_comments AS comment
    LEFT OUTER JOIN rs_comments AS sub_comment ON sub_comment.comment_parent = comment.id
    WHERE  comment.comment_parent ='0' 
    GROUP BY comment.id
    ORDER BY comment.id ASC");
    while( $get_comment = mysql_fetch_array( $rget_comments ) )
    {
        echo '+ <a href="comment.php?id=' . $get_comment['id'] . '">' . $get_comment['comment_name'] . '</a><br />';
        echo $get_comment['body'] . '<br />';

        echo '- <a href="comment.php?id=' . $get_comment['sub_id'] . '">' . $get_comment['sub_comment_name'] . '</a><br />';
        echo $get_comment['sub_body'] . '<br />';
    }

result:

+test comment
test comment 1 body
-sub comment 1
sub comment 1 body
+test comment 2
test comment 2 body

expected result:

+test comment 
test comment 1 body 
-sub comment 1 
sub comment 1 body 
-sub comment 2
sub comment 2 body 
+test comment 2
test comment 2 body 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T23:46:45+00:00Added an answer on June 2, 2026 at 11:46 pm

    GROUP BY comment.id causes this probrem. GROUP BY groups two records which have same id and different sub_id, to one. Remove it like this:

    SQL:

    SELECT DISTINCT 
        comment.id, comment.comment_name, comment.comment_body, (sub_comment.id) AS sub_id, (sub_comment.comment_name) AS sub_comment_name, (sub_comment.comment_body) AS sub_comment_body
        FROM rs_comments AS comment
          LEFT OUTER JOIN rs_comments AS sub_comment ON sub_comment.comment_parent = comment.id
        WHERE comment.comment_parent ='0' 
        ORDER BY comment.id ASC
    

    PHP:

    $flag = array();
    while( $get_comment = mysql_fetch_array( $rget_comments ) ) {
      if(!isset($flag[$get_comment['id']])) {
          echo '+ <a href="comment.php?id=' . $get_comment['id'] . '">' . $get_comment['comment_name'] . '</a><br />';
          echo $get_comment['body'] . '<br />';
          $flag[$get_comment['id']] = true;
      }
      if($get_comment['sub_id']) {
          echo '- <a href="comment.php?id=' . $get_comment['sub_id'] . '">' . $get_comment['sub_comment_name'] . '</a><br />';
          echo $get_comment['sub_body'] . '<br />';
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following method: public IEnumerable<Foo> GetFoo(int x, string y) { return from
Given the following: CriteriaQuery<SomeDTO> cQuery; CriteriaBuilder cb; Root<SomeClass> r; ... cQuery.select(cb.construct(SomeDTO.class, FIXED VALUE, r.get(SomeClass_.someValue)
I noticed that sometimes(randomly) my Mootools ajax request gets send twice. The second request
I would like to use a decorator on a function that I will subsequently
I have a mypage.cshtml as below <p><span>@r.get(My_Message)</span></p> Below is my entry in my resx
I want to filter out all entries in my access logs that have a
I am using nginx, web.py, fastcgi, and redis as my stack. Upon a post
I am using koala(1.3.0) with rails (3.0.7). This is how I use them. Link
The second assertion never executes in the unit test below: namespace Foo { public
I have the following class in my model: public class Notebook : TableServiceEntity {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.