我想将4个查询的结果显示在一个单独的html表中(SQL Server 2012,PHP,HTML)。我已经可以显示一个数据库表的结果,但是一旦我开始查询其他3个表,它只返回第一个表中的一行。
以下代码只有一个查询并且工作正常 - 它显示有关患者的几个信息(姓名,站,房间,导管,个人ID,导管插入日期......),目前有三个不同的患者在表中,因此html表显示3行:
<?php
require_once('header.php');
$today = date("d.m.y");
$yesterday = date("d.m.y", time() - 60 * 60 * 24);
$dbyesterday = date("d.m.y", time() - 2*(60 * 60 * 24));
?>
<div class="container" style="padding-top: 80px">
<div id="table_admin" class="span7">
<h3 id="name" style="color: orange">Visitenliste</h3>
</br>
<table class="table table-responsive table-hover">
<thead>
<tr>
<th id="tc">Station</th>
<th id="tc">Patientennummer</th>
<th id="tc">Zimmer</th>
<th id="tc">Name</th>
<th id="tc">Katheterart</th>
<th id="tc">Anlagedatum</th>
<th id="tc"><?php echo $dbyesterday; ?></th>
<th id="tc"><?php echo $yesterday; ?></th>
<th id="tc"><?php echo $today; ?></th>
</tr>
</thead>
<?php
require_once('server.php');
// DB-Query für die Visitenliste
$sql = "SELECT dbo.patients.Patientennummer, Vorname, Nachname, Station, Zimmer, Katheterart, Anlagedatum FROM dbo.patients INNER JOIN dbo.cathinsert ON dbo.patients.Patientennummer = dbo.cathinsert.Patientennummer ORDER BY Station ASC, Zimmer ASC";
$visdbyes = "SELECT (SELECT VisiteKind FROM dbo.visits WHERE VisiteDate = '$dbyesterday') AS VisiteKind";
$visyes = "SELECT (SELECT VisiteKind FROM dbo.visits WHERE VisiteDate = '$yesterday') AS VisiteKind";
$vistod = "SELECT (SELECT VisiteKind FROM dbo.visits WHERE VisiteDate = '$today') AS VisiteKind";
$result = sqlsrv_query($connection, $sql);
$result_vdy = sqlsrv_query($connection, $visdbyes);
$result_vy = sqlsrv_query($connection, $visyes);
$result_vt = sqlsrv_query($connection, $vistod);
$data = array();
while($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)){$data['row'] = $row;}
while($row = sqlsrv_fetch_array($result_vdy, SQLSRV_FETCH_ASSOC)) {$data['dby'] = $row;}
while($row = sqlsrv_fetch_array($result_vy, SQLSRV_FETCH_ASSOC)) {$data['yes'] = $row;}
while($row = sqlsrv_fetch_array($result_vt, SQLSRV_FETCH_ASSOC)) {$data['tod'] = $row;}
echo ("<tr class=\"clickable-row\" data-href=\"visitact.php?Patientennummer=".$row["Patientennummer"]."\">");
echo ("<td>".$data['row']["Station"]."</td>");
echo ("<td>".$data['row']["Patientennummer"]."</td>");
echo ("<td>".$data['row']["Zimmer"]."</td>");
echo ("<td>".$data['row']["Vorname"]." ".$data['row']["Nachname"]."</td>");
echo ("<td>".$data['row']["Katheterart"]."</td>");
echo ("<td>".$data['row']["Anlagedatum"]."</td>");
echo ("<td>".$data['dby']["VisiteKind"]."</td>"); //vorgestern
echo ("<td>".$data['yes']["VisiteKind"]."</td>"); // gestern
echo ("<td>".$data['tod']["VisiteKind"]."</td>"); //heute
?>
</table>
</div>
</div>
</body>
</html>
结果,我有一个包含3行的表格以及我需要的所有信息。 但是一旦我开始添加更多查询,附加信息就会正确显示,但仅适用于第一行!它是唯一显示的行。我真的无法弄明白,为什么会这样。 这是不起作用的代码(所有信息都显示正确,甚至是来自其他查询的信息,但只有一行 - >只有第一名患者,尽管有3名保存在数据库中,尽管第一个代码显示所有3名患者以正确的方式):
import java.util.Scanner;
import java.io.Serializable;
/* Class Node */
class Employee implements Serializable{
int ID;
String name;
String address;
Employee(int emp_ID, String emp_name, String emp_address){
ID = emp_ID;
name = emp_name;
address = emp_address;
}
public void print(){
System.out.println(ID);
System.out.println(name);
System.out.println(address);
}
@Override
public String toString() {
return ID + "-" + name + "-" + address;
}
}
class Node
{
protected Employee emp;
protected Node link;
public Object name;
public Node in;
/* Constructor */
public Node()
{
link = null;
emp = null;
}
/* Constructor */
public Node(Employee e,Node n)
{
emp = e;
link = n;
}
/* Function to set link to next Node */
public void setLink(Node n)
{
link = n;
}
/* Function to set data to current Node */
public void setData(Employee e)
{
emp = e;
}
/* Function to get link to next node */
public Node getLink()
{
return link;
}
/* Function to get data from current Node */
public Employee getData()
{
return emp;
}
}
/* Class linkedList */
class linkedList
{
protected Node start ;
protected Node end ;
public int size ;
/* Constructor */
public linkedList()
{
start = null;
end = null;
size = 0;
}
/* Function to check if list is empty */
/* Function to get size of the list */
/* Function to insert element at the begining */
public void insertAtStart(Employee e)
{
Node nptr = new Node(e,null);
nptr.setLink(start);
if(start == null)
{
start = nptr;
nptr.setLink(start);
end = start;
}
else
{
end.setLink(nptr);
start = nptr;
}
size++ ;
}
public void searchByName(){
}
public void deleteByName(){
}
}
/* Class CircularSinglyLinkedList */
public class CurrilarLinkedList
{
public static void main(String[] args)
{
int ID = 0;
String name = null;
String address = null;
Employee emp = null;
Scanner scan = new Scanner(System.in);
/* Creating object of linkedList */
linkedList list = new linkedList();
System.out.println("Circular Singly Linked List Test\n");
char ch;
/* Perform list operations */
do
{
System.out.println("\nCircular Singly Linked List Operations\n");
System.out.println("1. insert at begining");
System.out.println("2. delete by name");
System.out.println("3. search by name");
int choice = scan.nextInt();
switch (choice)
{
case 1 :
System.out.print("Please input an Employee \n");
Scanner myScanner = new Scanner(System.in);
System.out.println("Please input an Employee ID");
ID = myScanner.nextInt();
myScanner.nextLine();
System.out.println("Please input an Employee Name");
name = myScanner.nextLine();
System.out.println("Please input an Employee Address");
address = myScanner.nextLine();
emp = new Employee(ID,name,address);
list.insertAtStart(emp);
break;
case 2 :
break;
case 3 :
break;
default :
System.out.println("Wrong Entry \n ");
break;
}
System.out.println("\nDo you want to continue (Type y or n) \n");
ch = scan.next().charAt(0);
} while (ch == 'Y'|| ch == 'y');
}
}
我跳你可以帮忙! 提前谢谢,
德克
答案 0 :(得分:0)
我认为您应该每天使用一个查询,然后在while循环中检查日期。您还可以减少VisiteKind&#39; $ data数组中的字段:
$visd = "SELECT VisiteKind FROM dbo.visits";
$result_v = sqlsrv_query($connection, $visd);
$data = ['dby'=> [], 'yes'=> [], 'tod'=> []];
while($row = sqlsrv_fetch_array($result_v, SQLSRV_FETCH_ASSOC)) {
switch($row['VisiteKind']){
case $dbyesterday:
array_push($data['dby'],$row['VisiteKind']);
break;
case $yesterday:
array_push($data['yes'],$row['VisiteKind']);
break;
case $today:
array_push($data['tod'],$row['VisiteKind']);
break;
}
}