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
Control Breaks
Moderator: General Moderators
-
lloydsmods
- Forum Newbie
- Posts: 22
- Joined: Wed Aug 14, 2002 2:03 pm
- Location: NC
I've tried that
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
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
try this:
Code: Select all
$lastHeading = "";
while ($row = mysql_fetch_array($result)) {
$header = $rowї"header"];
$link = $rowї"link"];
if ($header <> $lastHeading) {
$lastHeading = $header;
echo "<b>$header</b><br>";
} else echo "$link<br>";
}