Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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