all rows but cat# @ first of each ++

wxdqz

New Member
I'm trying to list all the rows in a table in the format below, but also echo the $category<HR> each time it incriments. eg. there are 6 categoies and a handful of links in each.

Category is 2
Links are:
1, 2, 31, Mazamas, <!-- m --><a class="postlink" href="http://www.mazamas.o...">http://www.mazamas.o...</a><!-- m -->, huge portland based ...,
17, 2, 1, Mountain Shop, <!-- m --><a class="postlink" href="http://www.mountains...">http://www.mountains...</a><!-- m -->, Mountain Shop is the...,

i'm having a hard time getting my for/while loops right and have stalled out my computer a couple times. any help with this would really be appreciated. it seems like what's below is closest to the "right idea" but again, any help would be appreciated.

$query = "SELECT $link_table.ID AS LID, Clicks, Website, URL, $link_table.Description AS LDescription, $cat_table.ID AS CID, Category, $cat_table.Description AS CDescription FROM $cat_table, $link_table WHERE $cat_table.ID = $link_table.Cat_ID ORDER BY $cat_order, $links_order";
$result = mysql_query($query) or die("<p><b>Error:</b> No data exists.</p>\n\n");
$link_count = mysql_num_rows($result);

list($LID, $Clicks, $Website, $URL, $LDescription, $CID, $Category, $CDescription) = mysql_fetch_array($result);

for ($Count = 1; $Count <= $link_count; $Count++)
{
echo $Category; // print category
while ($Count==$CID) // then each time the CategoryID matches it's links, echo them
{
echo "\n\n<P><A href=http://www.phpbuilder.com/board/archive/index.php/$PHP_SELF?LID=$LID&URL=$URL&action=go".$link_target_window." title=\"$URL\">$Website</a>\n";
if ($LDescription == ""){ $LDescription = " (no description)"; }
echo "$LDescription\n";
echo "<DIV align=\"right\">\n<SPAN class=\"sm\">Clicks: $Clicks</SPAN>&nbsp;.&nbsp;\n";
echo "<A href=\"$PHP_SELF?action=modify_link&LID=$LID\" class=\"sm\">Modify</A>&nbsp;.&nbsp;\n";
echo "<A href=\"$PHP_SELF?action=remove_link&LID=$LID\" class=\"sm\">Remove</A></P>\n</DIV>\n\n";
}
}
 
Back
Top