Jump to content

Category display


sjones

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

[b]Categories[/b]
cat_id
parent_id
cat_name

[b]Vendors[/b]
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>";
}

?>


Link to comment
https://forums.phpfreaks.com/topic/5423-category-display/
Share on other sites

Archived

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

×
×
  • 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.