如何在PHP中显示SQL查询的特定结果

时间:2014-09-01 06:41:58

标签: php sql database forms mysqli

我想要做什么的信息。我创建了一个文本框,您输入患者姓名,然后从下拉框中单击该周,单击查找按钮后,它会显示患者姓名并收集所有数据并显示该周的护理提供者只要。对于数据库2000患者中的样本100名员工。我需要它来显示病人和在那一周内照顾那个人的员工,以便该人可以获得报酬。我已完成所有基本操作,只需要在结果方面提供帮助。谢谢你的帮助。

我的代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
  <title></title>
</head>

<body>
<!-- Look Up Patient Name -->
<form action="" name="patient_name" method="get">
<input type="text" name="" />

<!-- Display week -->
<select id="tst" size="1">
</select>

<script type="text/javascript">
/*<![CDATA[*/

function Weeks(year,day,id){
 var srt,ary=[],z0=1,sel=document.getElementById(id),date,months=
['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
 sel.options.length=0;
 sel.options[0]=new Option('Select Week');
 for (;z0<366+7;z0++){
  srt=new Date(year,0,z0-6,1);
  if (srt.getDay()==day&&srt.getFullYear()<=year){
   date=(day==0?months[srt.getMonth()]:nu(srt.getDate()))
   +'-'+(day==0?nu(srt.getDate()):months[srt.getMonth()])
   +'-'+srt.getFullYear()+'\n';
   sel.options[sel.options.length]=new Option(date,date);
  }
 }
 sel.selectedIndex=0;
}

function nu(nu){
 return nu>9?nu:'0'+nu;
}

Weeks(2014,0,'tst');

/*]]>*/
</script>
<input type="submit" value="Look Up" />
</form>
</body>
</html>


<!-- results -->
<?php
$con=mysqli_connect("localhost","root","","prive_ts");
// Check connection
if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$result = mysqli_query($con,"SELECT * FROM `info`");

echo "<table border='1' width='100%'>
<tr align='left'>
<th>Care Provider</th>
<th>Patient Name</th>
<th>Date of Service</th>
<th>Time In</th>
<th>Time Out</th>
<th>Remarks</th>
</tr>";

while($row = mysqli_fetch_array($result)) {
  echo "<tr>";
  echo "<td>" . $row['care_provider'] . "</td>";
  echo "<td>" . $row['patient_name'] . "</td>";
  echo "<td>" . $row['date_of_service'] . "</td>";
  echo "<td>" . $row['time_in'] . "</td>";
  echo "<td>" . $row['time_out'] . "</td>";
  echo "<td>" . $row['remarks'] . "</td>";
  echo "</tr>";
}

echo "</table>";

mysqli_close($con);
?>

1 个答案:

答案 0 :(得分:1)

您的SQL正在执行全选如果您想要特定结果,则需要查询它们,例如:

"SELECT * FROM database_name.info WHERE database_name.info.patient_name = '".$s_selected_patient.'"'

如果您没有使用PDO连接,我还建议您撤消输入:

$s_selected_patient = real_escape_string($s_selected_patient);