dongqiuge5435 2015-10-10 06:50
浏览 15

php选项值链接

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

?>

enter image description here

  • 写回答

3条回答 默认 最新

  • duanla3319 2015-10-10 07:06
    关注

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

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题