I have a table that looks like this:
id di_make di_model
1 Samsung TV656
2 Samsung TV555
3 Sony LCD33
I need to create a category and subcategories menu from this table...
LIKE THIS:
http://jsfiddle.net/7NYhe/500/
So i tried this:
$storecategories = "";
$storesubcategories = "";
$sql2="SELECT DISTINCT `di_make` FROM `products` ORDER BY id";
$query2 = mysqli_query($db_conx, $sql2);
$existCount2 = mysqli_num_rows($query2);
if ($existCount2!=0) {
while($row2 = mysqli_fetch_array($query2, MYSQLI_ASSOC)){
$di_makeC = $row2["di_make"];
/////Create sub categories/////////
$sql3="SELECT * FROM `products` WHERE di_make='$di_makeC'";
$query3 = mysqli_query($db_conx, $sql3);
$existCount3 = mysqli_num_rows($query3);
if ($existCount3!=0) {
while($row3 = mysqli_fetch_array($query3, MYSQLI_ASSOC)){
$di_modelC = $row3["di_model"];
$storesubcategories .='<li>'.$di_modelC.'</li>';
}
}
/////End of Create sub categories/////////
$storecategories .= '<li class="dropdown">'.$di_makeC.'
<ul>
'.$storesubcategories.'
</ul>
</li>';
}
}
However, the code above acts weirdly!
By that I mean, it will create the Categories and then create the subcategories BUT it will repeat the subcategories from the second category.
Like this:
http://jsfiddle.net/7NYhe/501/
Could someone please advice on this issue?
Thanks in advance.