我的结果页面的最后一部分出现问题


Issue with the last part of my result page

我在编码的最后部分需要帮助。我有它,当你在搜索框中查找一个名字时,它会调出那个人的信息。我需要帮助,当我键入人名时,我可以按周查找。所以在框中键入姓名,点击一周,然后点击提交按钮,它会显示该人在该周的所有结果。周部分工作不正常。

  Step 1: Type a first and last name  
  Step 2: Pick a week  
  Step 3: click on the submit button  
  Results: Shows the results of patient_name and all the care_providers in that week. 
  IN order care_provider, patient_name, date_of_service, time_in, time_out, and remarks. 
  I have the search box working to search for patient_name but not the week part.

CREATE TABLE `info` (
  `id` int(11) AUTO_INCREMENT,
  `care_provider` varchar(255),
  `patient_name` varchar(255),
  `date_of_service` date(10), //for the week part 
  `time_in` time(10),
  `time_out` time(10),
  `remarks` varchar(255),

代码:

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("prive_ts", $con);
$sql = "SELECT * FROM info";

if (isset($_POST['search_box']) && $_POST['search_box']) {
    $search_term = mysql_real_escape_string($_POST['search_box']);
    $sql .= " WHERE patient_name = '{$search_term}' ";
}
$query = mysql_query($sql) or die(mysql_error());
?>
<form name="search_form" method="POST" action="results38.php">
Search: <input type="text" name="search_box" value="" />
<input type="week" name="week" value="" />
<input type="submit" name="search" value="Look up Patient ...">
</form>
<table width="70%" cellpadding="5" cellspace="5">
<tr>
    <td><strong>Care Provider</strong></td>
    <td><strong>Patient Name</strong></td>
    <td><strong>Date of Time</strong></td>
    <td><strong>Time In</strong></td>
    <td><strong>Time Out</strong></td>
    <td><strong>Remarks</strong></td>
</tr>
<?php while ($row = mysql_fetch_array($query)) { ?>
<tr>
    <td><?php echo $row['care_provider']; ?></td>
    <td><?php echo $row['patient_name']; ?></td>
    <td><?php echo $row['date_of_service']; ?></td>
    <td><?php echo $row['time_in']; ?></td>
    <td><?php echo $row['time_out']; ?></td>
    <td><?php echo $row['remarks']; ?></td>
</tr>
<?php } ?>
</table>

您没有将"周"传递给SQL查询。

根据评论上的附加信息,你可能想试试这种

if (isset($_POST['search_box']) && $_POST['search_box']) {
    $search_term = mysql_real_escape_string($_POST['search_box']);
    $week = mysql_real_escape_string($_POST['week']);
    $sql .= " WHERE patient_name = '{$search_term}' AND WEEK(date_of_service) = {$week}";
}