php选项值链接

时间:2015-10-10 06:50:34

标签: php html mysql

我创建了一个下拉菜单,当点击下拉栏中类别的选项时,它可以链接到我的产品页面,但我没有链接它们,有没有人知道我的代码中有什么问题?

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);

?>

enter image description here

3 个答案:

答案 0 :(得分:1)

试试这个并使用mysqli而不是mysql,不推荐使用mysql(建议)

modelBuilder.Entity<T_SelectionList>()
                .HasMany(e => e.T_OrderDetails)
                .WithOptional(e => e.T_SelectionList)
                .HasForeignKey(e => e.SelectionList_ID); 

答案 1 :(得分:0)

执行此操作,将您要转发的网址设为值并将onchange()添加到<select>。并且您错过了?哪个服务器作为查询参数,

 echo "<option value='product.php category=".$roww['$cat_id']."'>".$row['cat_nm'];///here is the problem
                                 ^

它不是

echo "<option value='product.php?category=".$roww['$cat_id']."'>".$row['cat_nm'];///here is the problem
                                ^

<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>

答案 2 :(得分:0)

试试这个

$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);

?>