gk20 Posted March 21, 2006 Share Posted March 21, 2006 I have a table called item with fields category and item. I can display all distinct categories but I want to display them as links on my home page, so that when u click a category it displays all items in that category on a new page?Here my code for displaying each individual category: <?php include 'db.inc.php'; $cats = @mysql_query("SELECT DISTINCT category from item ORDER BY category"); echo '<b>  Category List<br></b>'; while ($row = mysql_fetch_array($cats)) { echo '<font color=red size="4">'; echo ' '; echo $row['category'] . '<br/>'; echo '</font>'; }?>Can anyone help? Quote Link to comment Share on other sites More sharing options...
blazing_bruce Posted March 21, 2006 Share Posted March 21, 2006 [!--quoteo(post=356919:date=Mar 21 2006, 05:39 PM:name=gk20)--][div class=\'quotetop\']QUOTE(gk20 @ Mar 21 2006, 05:39 PM) [snapback]356919[/snapback][/div][div class=\'quotemain\'][!--quotec--]I have a table called item with fields category and item. I can display all distinct categories but I want to display them as links on my home page, so that when u click a category it displays all items in that category on a new page?Here my code for displaying each individual category: <?php include 'db.inc.php'; $cats = @mysql_query("SELECT DISTINCT category from item ORDER BY category"); echo '<b>  Category List<br></b>'; while ($row = mysql_fetch_array($cats)) { echo '<font color=red size="4">'; echo ' '; echo $row['category'] . '<br/>'; echo '</font>'; }?>Can anyone help?[/quote]if you are trying to link them thenadd two more echos inside of the whilethat iswhile ($row = mysql_fetch_array($cats)) {//like file is$link = "$row['category'] "."php" echo '<font color=red size="4">'; echo ' '; echo '<a href='$link'>'; echo $row['category'] . '<br/>'; echo '</a>'; echo '</font>'; }i hope this will work as per your needs.Thank you,Karthikeyan Quote Link to comment Share on other sites More sharing options...
gk20 Posted March 22, 2006 Author Share Posted March 22, 2006 I've changed the code for displaying the different categories to this:while ($row = mysql_fetch_array($cats)) { session_register('category'); $_SESSION['category'] = $category; $category = $row['category']; echo '<font color=red size="4">'; echo ' '; echo '<a href="viewads.php">'; echo $row['category'] . '<br/>'; echo '</a>'; echo '</font>';}My page for displaying the different items is called viewads.php, i dont have any files called "categortyname".php, just this viewads.php file. At the moment it displays all items in the database, but I want it so that when a user clicks on a category name on the home page it will just display the items in that particular category??Is that possible?Heres the relevant code from my viewads.php file:session_register('cat'); $cat = $_SESSION['category']; $getcats = @mysql_query("SELECT DISTINCT category from item where category = '$cat' order by category asc");echo '<br>';while ($row = mysql_fetch_array($getcats)){ echo '<b><font color=red>Category: '; echo $row['category']; echo '<br><br></font></b>'; $catagain = $row['category']; $getitems = @mysql_query("SELECT itemname, cost, description, itemowner from item where category = '$catagain' order by itemname asc");............. etc display results }But it still doesnt work!! Does anybody understand what I'm trying to say??? 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.