PHP
using nested dropdown with ul and li

i am developing a project in which the menu bar consits of categories button and upon clicking the categories button all categories are dispplayed in dropdown and upon selecting each category the respective products to be displayed from data base. categories is working fine but the products of the last category are displaying for every category selected. pls help

<li><a href="javascript:void(0)" class="menulink">categories</a> <ul>
<li>
<?php
$category = get_rows($con,'select from categories'smile;
foreach($category as $cat)
{
?>
<a href="index.php?id=<?=$cat['id']?>"><?=$cat['name']?></a>
<ul>
<?php
if(isset($_GET['id'])){
$cat_id = $_GET['id'];
}
$product = get_rows($con,'select
from products where category_id ="'.$cat['id'].'"'smile;
//echo 'select * from products where category_id ="'.$cat['id'].'"';
foreach($product as $products)
{
?>
<li class="topline"><a href="index.php"><?=$products['name']?></a>
</li>
<?php
}
?>
</ul>
<?php
}
?>
</li>

                                                        </ul>

                                                    </li>
i am developing a project in which the menu bar consits of categories button and upon clicking the categories button all categories are dispplayed in dropdown and upon selecting each category the respective products to be displayed from data base. categories is working fine but the products of the last category are displaying for every category selected. pls help &lt;li&gt;&lt;a href=&quot;javascript:void(0)&quot; class=&quot;menulink&quot;&gt;categories&lt;/a&gt; &lt;ul&gt; &lt;li&gt; &lt;?php $category = get_rows($con,&#039;select * from categories&#039;); foreach($category as $cat) { ?&gt; &lt;a href=&quot;index.php?id=&lt;?=$cat[&#039;id&#039;]?&gt;&quot;&gt;&lt;?=$cat[&#039;name&#039;]?&gt;&lt;/a&gt; &lt;ul&gt; &lt;?php if(isset($_GET[&#039;id&#039;])){ $cat_id = $_GET[&#039;id&#039;]; } $product = get_rows($con,&#039;select * from products where category_id =&quot;&#039;.$cat[&#039;id&#039;].&#039;&quot;&#039;); //echo &#039;select * from products where category_id =&quot;&#039;.$cat[&#039;id&#039;].&#039;&quot;&#039;; foreach($product as $products) { ?&gt; &lt;li class=&quot;topline&quot;&gt;&lt;a href=&quot;index.php&quot;&gt;&lt;?=$products[&#039;name&#039;]?&gt;&lt;/a&gt; &lt;/li&gt; &lt;?php } ?&gt; &lt;/ul&gt; &lt;?php } ?&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt;

8
0
1
live preview
enter atleast 10 characters
WARNING: You mentioned %MENTIONS%, but they cannot see this message and will not be notified
Saving...
Saved
With selected deselect posts show selected posts
All posts under this topic will be deleted ?
Pending draft ... Click to resume editing
Discard draft