在php中使用dropdow过滤数据[重复]

o7jaxewo  于 2023-04-04  发布在  PHP
关注(0)|答案(1)|浏览(74)

此问题在此处已有答案

(29个答案)
What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must be of type mysqli_result and such(1个答案)
昨天关门了。
我尝试显示一些数据的下拉选项从mySQL
当用户选择选项“美国”并单击“提交”时,该页将转到下一页并仅显示美国的数据
下面是我的store.php代码

<form method=POST action="filter.php" name="filter">

    <select name="fbike" id="fbike">
        <option value="" disabled selected>category</option>
        <optgroup label="bike">
            <option value="city_bike">city</option>
            <option value="mountain_bike">mountain</option>
            <option value="bmx_bike">bmx</option>
        </optgroup>
        <option value="clothes">clothes</option>
        <option value="accessory">accessory</option>
         </select>
         <input name="submit" type="submit" value="show" />
</form>

这里是我的第二页filter.php

$link=mysqli_connect("localhost","root","","rider_shop");
if(mysqli_connect_errno())
   exit("there is an error".musqli_connect_error());


if(isset($_POST['submit'])){
    $selected_value=$_POST['fbike'];
    if($selected_value=='city_bike'){
        $drop="SELECT * FROM rider_products WHERE fbike='city'";
    }
    else if($selected_value=='mountain_bike'){
        $drop="SELECT * FROM rider_products WHERE fbike='mountain'";
    }
    else{
        exit("it does not exist");
    }
    $result=mysqli_query($link,$drop);
        while($row=mysqli_fetch_array($result)){
            echo$row['fbike'].'-'.$satr['price'].'<br/>';
        }
}

我尝试了上面的代码,但我得到了2个错误
未定义的索引:Copyright © 2018 www.jsjsj.com All Rights Reserved.
Copyright © 2018 - 2019 www.wamp64.com All Rights Reserved.粤ICP备15048888号-1
第14行是

$selected_value=$_POST['fbike'];

第36行是另一个过滤器,它可以自己工作,但当我添加下拉过滤器时,它不再工作,我有那个错误,他的代码是:

$min_price=$_POST['min_price'];
$max_price=$_POST['max_price'];
$query="SELECT * FROM rider_products WHERE price BETWEEN $min_price AND $max_price";
$result=mysqli_query($link,$query);
while($row=mysqli_fetch_array($result)){
    echo$row['fbrand'].'-'.$row['price'].'<br/>';
}
ccrfmcuu

ccrfmcuu1#

问题是你得到一个空的结果,因为没有条目与指定的fbike匹配,从mysqli_query返回$result为FALSE...你必须检查你得到的行。

相关问题