georgebates Posted December 11, 2009 Share Posted December 11, 2009 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 Quote Link to comment Share on other sites More sharing options...
vinpkl Posted December 11, 2009 Share Posted December 11, 2009 echo the categories names in a drop down. when the user choose any option from drop down then set that value and echo the results. if(isset($_POST['category_name'])); vineet Quote Link to comment Share on other sites More sharing options...
georgebates Posted December 12, 2009 Author Share Posted December 12, 2009 ok but how do i get it to display only the links from that category thanks Quote Link to comment Share on other sites More sharing options...
vinpkl Posted December 12, 2009 Share Posted December 12, 2009 if they are stored in your database table column then just call that table column in your query. $query="select links from tablename where category_name=category name"; vineet Quote Link to comment 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.