phpretard Posted February 8, 2009 Share Posted February 8, 2009 I am trying to display links on a page read from my DB. I would like them to display: CAT 1 Link 1 Link 2 Link 3 etc... CAT 2 Link 1 Link 2 Link 3 etc... I know the code below is silly but it's to illustrate my needs. The DB rows are setup as is in the code...the echo is silly <? $result_links = mysql_query("SELECT * FROM links ORDER by cat"); while($row = mysql_fetch_array($result_links)) { $id=$row['id']; $cat=$row['cat']; $url=$row['url']; $display=$row['display']; echo"<h4>Category 1</h4>"; echo"all the links assc. with category 1"; echo"<h4>Category 2</h4>"; echo"all the links assc. with category 2"; echo"<h4>Category 3</h4>"; echo"all the links assc. with category 3"; echo"<h4>Category 4</h4>"; echo"all the links assc. with category 4"; } ?> Thanks PHP FREAKS! Link to comment https://forums.phpfreaks.com/topic/144362-simple-problemneed-ideas/ Share on other sites More sharing options...
.josh Posted February 8, 2009 Share Posted February 8, 2009 $result_links = mysql_query("SELECT * FROM links ORDER by cat"); while($row = mysql_fetch_array($result_links)) { $id=$row['id']; $cat=$row['cat']; $url=$row['url']; $display=$row['display']; echo ($prevcat != $cat)? "<h4>$cat</h4>" : ""; echo "$id $link $display"; // whatever format you want $prevcat = $cat; } ?> Link to comment https://forums.phpfreaks.com/topic/144362-simple-problemneed-ideas/#findComment-757547 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.