Php 在子字符串而不是全文中查找查询

Php 在子字符串而不是全文中查找查询,php,forms,mysqli,substring,Php,Forms,Mysqli,Substring,我已经创建了一个搜索功能。它可以通过全文找到地址,但如何通过地址的部分进行查询搜索?例如,完整地址为paya lebar Road Blk27,如何设置该地址,以便用户只需键入paya,它仍会显示 搜索表单 <h2>View Patient Records</h2> <body> <form action="display_patient.php" method="post"> <p>Select: <select name=

我已经创建了一个搜索功能。它可以通过全文找到地址,但如何通过地址的部分进行查询搜索?例如,完整地址为
paya lebar Road Blk27
,如何设置该地址,以便用户只需键入
paya
,它仍会显示

搜索表单

<h2>View Patient Records</h2>


<body>
<form action="display_patient.php" method="post">
<p>Select:
<select name="patient_var" >
<?php 
$value = array(view_all, name, address); 
foreach ($value as $option)
{
    echo '<option value="'.$option.'"' . (isset($_POST['patient_var']) && $_POST['patient_var'] == $option ? ' selected' : '') . '>' . $option . '</option>';
}

?>
</select>

<input type="text" name="typed" value="" />

<input type ="submit" value="submit" />
</form>
</p>

<p>

<?php
if (isset($_POST['patient_var'])) {

    $type = $_POST['typed'];
    $select = $_POST['patient_var'];
 if ($select == 'view_all') {
     echo "<table border='1'>"; 
 echo "<tr>\n"; 
echo "<th>ID</th>\n"; 
echo "<th>Patient Name</th>\n"; 
echo "<th>Age</th>\n";
echo "<th>NRIC</th>\n";
echo "<th>Birth Date</th>\n";
echo "<th>Medical Allergies</th>\n";
echo "<th>Medical History</th>\n";
echo "<th>Phone</th>\n";
echo "<th>Address</th>\n";
echo "<th>Doctor Assigned</th>\n";
 echo "</tr>"; 

    $pat_set = default_patient();

     while ($mo = mysqli_fetch_array($pat_set)) {
                echo "<tr>"; 
 echo "<td>" . $mo['id'] . "</td>"; 
 echo "<td>". $mo['name'] . "</td>"; 
  echo "<td>". $mo['age'] . "</td>"; 
   echo "<td>". $mo['nric'] . "</td>"; 
    echo "<td>". $mo['birthdate'] . "</td>";
     echo "<td>". $mo['medical_allergies'] . "</td>";
      echo "<td>". $mo['medical_history'] . "</td>";
       echo "<td>". $mo['phone'] . "</td>";     
 echo "<td>". $mo['address'] ."</td>"; 
        echo "<td>". $mo['doctor_assigned'] . "</td>";
 echo "</tr>"; 
            }
 } 




else {
    echo "<table border='1'>\n"; 
echo "<tr>\n"; 
echo "<th>ID</th>\n"; 
echo "<th>Patient Name</th>\n"; 
echo "<th>Age</th>\n";
echo "<th>NRIC</th>\n";
echo "<th>Birth Date</th>\n";
echo "<th>Medical Allergies</th>\n";
echo "<th>Medical History</th>\n";
echo "<th>Phone</th>\n";
echo "<th>Address</th>\n";
echo "<th>Doctor Assigned</th>\n";
 echo "</tr>";

  $patients_set = 
 find_patients($select, $type);

 while ($row = mysqli_fetch_array($patients_set)) 
 { echo "<tr>"; 
 echo "<td>" . $row['id'] . "</td>"; 
 echo "<td>". $row['name'] . "</td>"; 
  echo "<td>". $row['age'] . "</td>"; 
   echo "<td>". $row['nric'] . "</td>"; 
    echo "<td>". $row['birthdate'] . "</td>";
     echo "<td>". $row['medical_allergies'] . "</td>";
      echo "<td>". $row['medical_history'] . "</td>";
       echo "<td>". $row['phone'] . "</td>";     
 echo "<td>". $row['address'] ."</td>"; 
        echo "<td>". $row['doctor_assigned'] . "</td>";
 echo "</tr>"; }

}  

}//end of if post submit

?>
</p>
查看患者记录
选择:


使用类似“%$searchParam%”的
而不是Mysql中的
=$searchParam
来搜索列是否具有特定的字符串用途

范例

SELECT * FROM table WHERE column LIKE '%somestring%'; 
就你而言,试试这个

$typed = $_POST['typed'];
然后像这样进行Mysql查询

$query = "select * from table where Address LIKE '%".$typed."%' ";

您忘记发布您的功能:查找患者($select,$type); 但我想您需要一个地址varchar字段的部分字符串查询,该字段如下所示:

select * from MyTable where myColumn like '%myPartialString%';

此类型的查询将返回其中包含“MyPartialString”的所有行。

在sql查询中使用
LIKE%%