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

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.