Control Breaks

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
lloydsmods
Forum Newbie
Posts: 22
Joined: Wed Aug 14, 2002 2:03 pm
Location: NC

Control Breaks

Post 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
MattF
Forum Contributor
Posts: 225
Joined: Sun May 19, 2002 9:58 am
Location: Sussex, UK

Post by MattF »

"SELECT * FROM links GROUP BY type"
lloydsmods
Forum Newbie
Posts: 22
Joined: Wed Aug 14, 2002 2:03 pm
Location: NC

I've tried that

Post 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
fatalcure
Forum Contributor
Posts: 141
Joined: Thu Jul 04, 2002 12:57 pm
Contact:

Post 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;
Post Reply