在 PHP 中按大小搜索查询

我希望我的网站在单击移动版本上选择输入菜单中的任何尺寸选项时搜索属于特定尺寸的任何产品,例如移动版本上www.brastop.com中的按尺寸购物菜单。我的问题是如何从选项标签中提取大小变量并将其放入 sizeresult.php 中的选择查询中。下面是我的代码:

  1. 用于选择菜单

    <option selected disabled>Select Your size:</option>

    <?php


    $get_sizes = "select * from sizes";

    $run_sizes = mysqli_query($dbc,$get_sizes);


    while ($row_sizes=mysqli_fetch_array($run_sizes)){


        $size_id = $row_sizes['size_id'];

        $size_name = $row_sizes['size'];


        echo "


          <option value='sizeresults.php?$size_id'> $size_name </option>



          ";


    }


    ?>

</select>


我的问题是如何从选项标记中提取 $size_name 并将其放在下一个代码片段第一行 WHERE 子句后面的两个单引号之间,我在其中编写了sizes.size = ='%$size_name%'


MMTTMM
浏览 98回答 2
2回答

人到中年有点甜

您可以执行以下操作来修复代码。写下你的表格如下。&nbsp;<form action="sizeresults.php" method="POST"><!-- use post method not must but safe -->&nbsp;<select name="size"&nbsp; onchange="this.form.submit()"><!-- i assumed the select name to be size -->&nbsp; &nbsp; &nbsp;<option selected disabled>Select Your size:</option>&nbsp; &nbsp; &nbsp;<?php&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$get_sizes = "select * from sizes";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$run_sizes = mysqli_query($dbc,$get_sizes);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;while ($row_sizes=mysqli_fetch_array($run_sizes)){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$size_id = $row_sizes['size_id'];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$size_name = $row_sizes['size'];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;echo "<option value='$size_name'> $size_name </option>";//changed value&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&nbsp; &nbsp; &nbsp;?>&nbsp;</select>在 sizeresults.php 文件中的 $run_products = mysqli_query(... 上方添加以下行。$size_name=$_POST['size'];//用于获取查询中使用的选项的值。

一只名叫tom的猫

需要捕获选择更改事件并从选择框中获取值/id。在“search.php”上发送 ajax 请求并发送响应。接收ajax响应。
打开App,查看更多内容
随时随地看视频慕课网APP