Jump to content


Photo

Category display


  • Please log in to reply
2 replies to this topic

#1 sjones

sjones
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 21 March 2006 - 02:56 PM

Hello, I am trying to select a category and then if it is a parent category, I would like to display with links all of the child categories with the vendors link that is in the child category. EXAMPLE

Choose Category --> Submit --> (Query db to see if this is a parent category - if so echo)

Main Category

->Sub Category 1

-->Vendor 1 (link)
-->Vendor 2 (link)
->Sub Category 2
-->Vendor 1 (link)
->Sub Category 3
-->Vendor 1 (link)
-->Vendor 2 (link)

If the category choosen was not a parent category then display vendors in that category EXAMPLE

Main Category (is not a parent category)
-->Vendor 1 (link)
-->Vendor 2 (link)


The two tables in the DB that are controling this are

Categories
cat_id
parent_id
cat_name

Vendors
vendor_id
vendor_name
cat_id
file_name
active_id


I know this is probably a simple solution, but I have tried for about 5 days to code this.
Can someone please help.

Here is the code: just one of the hundreds that I have tried.

<?php
session_start();
include ('../connections/mysql_connect.php');
if (!isset($_POST['submit'])) {

echo "<span class='content_blank'><strong>Please choose a category...</strong></span><BR><BR>";
echo "<form method='POST' action='cat_nav.php'>
<select name='cat_id'>
<option>- Please select one -</option>\n";
$qry = mysql_query("SELECT * FROM categories WHERE parent_id = 0;");
while($rows = mysql_fetch_assoc($qry)) {
echo "<option value='".$rows['cat_id']."'>".$rows['cat_name']."</option>\n";
}
echo "</select>

<input name='submit' type='submit' value='View'>
</form>";
}

?>




#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 21 March 2006 - 03:03 PM

Though fairly complex, I usually use nested sets to organize data into a hierarchy. Maybe [a href=\"http://www.phpriot.com/d/articles/php/application-design/nested-trees-1/index.html\" target=\"_blank\"]this[/a] article will help you.

#3 sjones

sjones
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 21 March 2006 - 03:22 PM

Thanks for the info, I read that article and that is way to complex for me right now.

That will be a project for down the road.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users