发布我的结果页面的最后一部分

时间:2014-09-07 23:38:57

标签: php mysql database forms

我在编码的最后部分需要帮助。我有它,当你在搜索框中查找一个名称,它拉起那些人的信息。我需要帮助的地方,当我输入一个人名时,我可以查看几周。因此,在框中键入名称,单击一周,然后单击提交按钮,它将显示该周内该人的所有结果。周部分工作不正常。

  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>

1 个答案:

答案 0 :(得分:0)

您没有将“周”传递给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}";
}