Jump to content


This topic is now archived and is closed to further replies.


Category display

Recommended Posts

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)

[b]Main Category

->Sub Category 1[/b]
-->Vendor 1 (link)
-->Vendor 2 (link)
[b]->Sub Category 2[/b]
-->Vendor 1 (link)
[b]->Sub Category 3[/b]
-->Vendor 1 (link)
-->Vendor 2 (link)

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

[b]Main Category [/b] (is not a parent category)
-->Vendor 1 (link)
-->Vendor 2 (link)

The two tables in the DB that are controling this are



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.

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'>


Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites


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.