Jump to content

Simple Problem...Need Ideas


phpretard

Recommended Posts

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

$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;
  }

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.