Jump to content

Please help!!


georgebates

Recommended Posts

Hi there,

 

I have found some code for displaying some links in a database by category. There is one table in the database that has the listing information and another table that has the categories (I did this so that i don't have to change every single entry if i want to change a category). The way that it currently displays it is that it put them in a table sorted by the category names but i want it so that the user choses which category they want displayed and it only displays the entry's based on which category they choose.

 

Heres the code:

<?php 
$myResult = mysql_query('SELECT ref_links.*, ref_categories.category_name FROM ref_links, ref_categories WHERE ref_links.ref_categories_id=ref_categories.id ORDER BY ref_categories_id, ref_links.topic_name', $connectID)
  or die ("Unable to select from database");

while ($row=mysql_fetch_array($myResult, MYSQL_ASSOC)) {
  $thisCat= $row['category_name'];
//print the category heading, but only once for the listings in that catagory
if ($lastCat<>$thisCat) { // true first time($lastCat not set), and each time a new category is found
			print "<h2>".$row['category_name']."</h2>";  // print the next category heading
	}
	print '<div id="ref_links">';
	print "<h3>Painting Name: ".$row['topic_name']."</h3>\n";
	print "<p>Price: ".$row['topic_desc']."</p>\n";
	print '<br/>'."\n";
	print "<img src=".$row['topic_url']." />";

  $lastCat = $row['category_name']; // record which category this listing was in so we can test if the cat. changes
  
    print "</div>\n";  //end of ref_links div
}
?>

 

Hope someone can help me

 

Thanks

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.