I created a dropdown menu and when click on the option on the category in the drop down bar, it can link to my product page, but i failed to linked them, does anyone know what is the problems in my code?
enter code here
$link=mysql_connect("localhost","root","")or die("Can't Connect...");
mysql_select_db("fyp",$link) or die("Can't Connect to Database...");
$query="select * from category ";
$res=mysql_query($query,$link);
while($row=mysql_fetch_assoc($res))
{
echo "<option value='product.php category=".$roww['$cat_id']."'>".$row['cat_nm'];///here is the problem
$qq = "select * from subcat where parent_id=".$row['cat_id'];
$ress = mysql_query($qq,$link) or die("wrong delete subcat query..");
while($roww = mysql_fetch_assoc($ress))
{
echo "<option value='".$roww['subcat_id']."'> ---> ".$roww['subcat_nm'];//here is the problems
}
}
mysql_close($link);
?>
do it like this, give url you want to edirect to in value and add onchange()
to <select>
. And you have missed ?
which server as query parameter,
echo "<option value='product.php category=".$roww['$cat_id']."'>".$row['cat_nm'];///here is the problem
^
it shud be
echo "<option value='product.php?category=".$roww['$cat_id']."'>".$row['cat_nm'];///here is the problem
^
and
<select onchange="this.options[this.selectedIndex].value && (window.location = this.options[this.selectedIndex].value);">
<option value="">Select...</option>
<option value="product.php?category=".$roww['$cat_id']."">Product 1</option>
<option value="product.php?category=".$roww['$cat_id']."">Prosuct 2</option>
</select>
Try this
$link=mysql_connect("localhost","root","")or die("Can't Connect...");
mysql_select_db("fyp",$link) or die("Can't Connect to Database...");
$query="select * from category ";
$res=mysql_query($query,$link);
while($row=mysql_fetch_assoc($res))
{
echo "<option value='product.php category=".$row['$cat_id']."'>".$row['cat_nm'];///here is the problem
$qq = "select * from subcat where parent_id=".$row['cat_id'];
$ress = mysql_query($qq,$link) or die("wrong delete subcat query..");
while($roww = mysql_fetch_assoc($ress))
{
echo "<option value='".$roww['subcat_id']."'> ---> ".$roww['subcat_nm'];//here is the problems
}
}
mysql_close($link);
?>
Try this and use mysqli instead of mysql, mysql is deprecated(Suggestion)
$link=mysqli_connect("localhost","root","")or die("Can't Connect...");
mysqli_select_db($link,"fyp") or die("Can't Connect to Database...");
$query="select * from category";
<select onselect='goUrl(this.value)' id="cval" name="cval">
$res=mysqli_query($link,$query);
while($row=mysqli_fetch_assoc($res))
{
echo "<option value='".$row['cat_id']."'>".$row['maincatname']."</option>";
$qq = "select * from subcat where parent_id=".$row['cat_id'];
$ress = mysqli_query($link,$qq) or die("wrong delete subcat query..".mysqli_error($link));
while($roww = mysql_fetch_assoc($ress))
{
echo "----><option value='".$roww['subcat']."'>".$roww['subcatname']."</option>";
}
}
</select>
mysqli_close($link);
?>
<script>
function goUrl(catgry)
{
window.location.href='product.php?category='+catgry;
}
</script>