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! Quote 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; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/144362-simple-problemneed-ideas/#findComment-757547 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.