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
https://forums.phpfreaks.com/topic/244622-php-ordering-scattered-rows/
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
     }

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.