Jump to content

php ordering scattered rows


dannybrazil

Recommended Posts

Hello,

 

I have a DB with lots of rows...some sort of comments for each article.

 

Lets say the articles have an ID (AR001,AR002...AR100).

 

Each author write articles freely, so I cant know how many each has.

 

Now each article gets various numbers of comments, which I cannot know before hand, and the ROW ID is mixed.

 

I want to print the authors, their articles (ordered) and comments for each.

 

The thing is...how do I capture ONLY ONCE the article code? I mean id AR001 has 100 comments, how do I get JUST the article code ONCE and then another while loop to get the comments.

 

Ex.

 

Danny Sheps

 

Article 1

comment 1

comment n

 

Article 2

comment 1

comment n

 

Article n

comment 1

comment n

 

hope you got it....Thanks

 

 

Link to comment
Share on other sites

$r = mysql_query('select articles');
while($a = mysql_fetch_assoc($r) {

     echo "article".$a['article_name'];
     
     $r2 = mysql_query('select commects where article = '. $a['articleID']);
     while($a2 = mysql_fetch_assoc($r2) {
           //echo comment here
     }

}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.