我想在导航栏中显示所选或单击的产品类型的品牌名称。 SQL代码可以,因为我已经测试过了。我不知道php有什么问题。我试图知道用Javascript选择了哪个项目。
<ul class="nav navbar-nav ">
<li class="active">
<a href="index.php">Home</a>
</li>
<li>
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Products <span class="caret"></span></a>
<ul class="dropdown-menu multi-level" id="productNav">
<?php
$get_p_cats = "select * from category";
$run_p_cats = mysqli_query($con,$get_p_cats);
$selectedProductID="<script type='text/javascript'>
var ul = document.getElementById('productNav');
ul.onclick = function(event) {
var target = event.target;
alert(event.target.innerHTML);
}; </script>";
echo "<script type='text/javascript'>
var ul = document.getElementById('productNav');
ul.onclick = function(event) {
var target = event.target;
alert(event.target.innerHTML);
}; </script>";
$get_specificBrand="select distinct i.brandId,b.brandName
from brand b, item i
where b.brandId=i.brandId and i.categoryId=$selectedProductID";
$run_specificBrand = mysqli_query($con,$get_specificBrand);
while($row_p_cats = mysqli_fetch_array($run_p_cats) ){
$p_cat_id = $row_p_cats['catId'];
$p_cat_title = $row_p_cats['catName'];
echo "<li class='dropdown-submenu'><a class='dropdown-toggle' data-toggle='dropdown' href='shop.php?p_cat=$p_cat_id'> $p_cat_title </a>
<ul class='dropdown-menu'>
<li><a href='#'>p_specificBrandtitle</a></li></ul></li>";
}
?>
</ul>
</li></ul>