从数据库中的两个输入框中搜索数据的PHP

时间:2019-04-22 06:10:28

标签: php mysql

这是警告显示:mysqli_fetch_assoc()期望参数1为mysqli_result,布尔值在

中给出

在我的数据库中

-------------------------------------------------
'ID   Bus_Name   Stopage_Name   Time   Distance
-------------------------------------------------
 1    Radha       Chandni       5.00      0
-------------------------------------------------
 2    Radha       Metro         5.30      50
-------------------------------------------------
 3    Radha       Park          6.00      100
-------------------------------------------------
 4    Radha       Lal           6.30      150
-------------------------------------------------
 5    Rani        Lal           5.00      0
-------------------------------------------------
 6    Rani        Metro         6.00      100
-------------------------------------------------
 7    Rani        Crossing      6.30      150
-------------------------------------------------
 8    Rani        Bazzar        7.00      250
-------------------------------------------------
 9    Crish       Lal           12.00     0
-------------------------------------------------
 10   Crish       Metro         12.30     50
-------------------------------------------------
 11   Crish       Crossing      01.00     100
-------------------------------------------------
 12   Crish       Bazzar        01.30     150
-------------------------------------------------
 13   Crish       Mill          02.00     200'
-------------------------------------------------



<form action="" method="POST">
    <input type="text" name="txtStart">
    <input type="text" name="txtEnd">
    <input type="submit" value="Search" name="search">
</form>'

PHP

<?php
if(isset($_POST['search']))
{   
  $strkey1=$_POST['txtStart'];
  $strkey2=$_POST['txtEnd'];
  $sql="SELECT *FROM  bus_details WHERE Stopage_Name BETWEEN 
        $strkey1 AND $strkey2";
  $query=mysqli_query($ccon,$sql);
  while($row=mysqli_fetch_assoc($query))
  {'
  ?>'       
  '<table>
      <tr>
        <th>BUS NAME</th>
        <th>STOPAGE NAME</th>
        <th>TIME</th>
        <th>DISTANCE</th>
    </tr>'

1 个答案:

答案 0 :(得分:0)

根据我的理解,您正在varchar数据类型中进行搜索,而搜索的方式是错误的。您必须将值放在single quotedouble quote

之间
$sql="SELECT * FROM  bus_details WHERE Stopage_Name BETWEEN 
    '$strkey1' AND '$strkey2' ";

如何将BETWEEN应用于varchar DataType?基本上,您可以将BETWEEN用于日期,数字等范围。

您的查询应类似于

sql="SELECT * FROM  bus_details WHERE Stopage_Name LIKE 
    '%$strkey1%' AND '%$strkey2%' ";

请参考MYSQL BETWEEN