简体   繁体   中英

How can I display specific results from an SQL query in PHP

Info on what I am trying to do. I made a text box where you enter the patient name and then you click on the week from a drop down box and after you click on the look up button it displays the patient name and collects all the data and shows the care provider for that week only. For sample 100 employees in the database 2000 patients. I need it to display the patient and the employees who cared for that person during that week so that person can get paid. I have all the basic done just need help on the result side. Thanks for your help.

My code:

<!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);
?>

Your SQL is doing a select all If you want specific results, you need to query for them, for example:

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

I would also recommend escaping your input if you aren't using PDO connections like so:

$s_selected_patient = real_escape_string($s_selected_patient);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM