Page 1 of 1

Control Breaks

Posted: Wed Aug 14, 2002 2:03 pm
by lloydsmods
Does anyone know how to do this?:

I have a mySQL table called "links". I want to query the table and display the results grouped by the type of link with a header for each group. For example:

NEWS SITES
link...
link...
link...

FAN SITES
link...
link...
link...

I understand how to do this sort of thing with COBOL or RPG (gads!) but I'm learning PHP and mySQL so I'm not sure how to do this. I know how to select and group the results, but I can't figure out how to do a single level control break loop to display the output the way I want it.

Can anyone give me some pointers?

-Lloyd Bailey

Posted: Wed Aug 14, 2002 2:21 pm
by MattF
"SELECT * FROM links GROUP BY type"

I've tried that

Posted: Wed Aug 14, 2002 7:37 pm
by lloydsmods
So how does this act as a control break? That still doesn't get the heading between groups.

If I include the heading in the echo statement it prints every time. I just want it to print once, then print the links that are in that group, print a new heading, then print the links in that group.

Has anyone got any suggestions?

-Lloyd

Posted: Wed Aug 14, 2002 7:55 pm
by fatalcure
try this:

Code: Select all

$lastHeading = "";

while ($row = mysql_fetch_array($result)) {
     $header = $rowї"header"];
     $link = $rowї"link"];
     if ($header <> $lastHeading) &#123;
          $lastHeading = $header;
          echo "<b>$header</b><br>";
     &#125; else echo "$link<br>";
&#125;