我有一张表“测试”。
Category | Heading | Tests |
HB |Hematology | HB |
TC |Hematology | TC |
DC |Hematology | Neutrophil|
DC |Hematology | Monocyte |
DC |Hematology | Lymphocyte|
DC |Hematology | Basophil |
KFT |Biochemistry| Urea |
KFT |Biochemistry| S.Creatinine |
KFT |Biochemistry| S.Uric Acid |
Lipid Profile|Biochemistry| Cholesterol |
Lipid Profile|Biochemistry| Triglyceride |
Lipid Profile|Biochemistry|HDL Cholesterol|
Lipid Profile|Biochemistry|LDL Cholesterol|
Albumin |Biochemistry| Albumin |
Globulin |Biochemistry| Globulin |
Amylase |Biochemistry| Amylase |
VDRL | Serology | VDRL |
HIV | Serology | HIV |
HCV | Serology | HCV |
Dengue | Serology | NS1 Antigen |
Dengue | Serology | IgG Antibody|
Dengue | Serology | IgM Antibody|
Urine R/E | Urine | Color |
Urine R/E | Urine | Transparency|
Urine R/E | Urine | Reaction |
另一张表“病人”
Name | Tests | P_no
John | HB | 1
Krish | HB | 2
Krish | TC | 2
Krish | DC | 2
Krish | Urine R/E | 2
Krish | Dengue | 2
Amy | HB | 3
Amy | TC | 3
Amy | DC | 3
Amy | KFT | 3
Amy | Albumin | 3
Amy | HIV | 3
Amy | Dengue | 3
Amy | Urine R/E | 3
我有一个表格“条目”。我放置了一个文本框来输入患者编号,以获取报告输入的测试详细信息。
Patient Number : Textbox
Submit Button
在文本框中输入数字“3”并提交表格,必须根据患者编号显示另一个表格“Result.php”,如下所示。
Patient No. : 3 Patient Name : Amy
Tests for Hematology
HB HB Textbox
TC TC Textbox
DC Neutrophil Textbox
Monocyte Textbox
Lymphocyte Textbox
Basophil Textbox
Tests for Biochemistry
KFT Urea Textbox
S.Creatinine Textbox
S.Uric Acid Textbox
Albumin Albumin Textbox
Tests for Serology
HIV HIV Textbox
Dengue NS1 Antigen Textbox
IgG Antibody Textbox
IgM Antibody Textbox
Tests for Urine
Urine R/E Color Textbox
Transparency Textbox
Reaction Textbox
需要帮助才能获得“Result.php”,如图所示。任何帮助将不胜感激。
答案 0 :(得分:0)
一个简单的方法就是有这样的查询:
SELECT tests.Category, tests.Heading, tests.Tests FROM patient
JOIN tests ON tests.Category = patient.Tests
WHERE patient.P_no = ?
ORDER BY tests.Heading, tests.Category
这样您就可以检索需要显示的所有数据。 然后为了显示它,可以循环结果集并存储最后一个标题和类别,如果当前元素具有不同的标题或类别,则打印它,否则在那里打印一个空字符串。
希望有助于理念。
关于如何显示数据的部分假设您将数据作为名为$rows
的关联数组提取。
$lastHeading = "";
$lastCategory = "";
foreach($rows as $row) {
//check if there is a new heading (if so, print it and update the $lastHeading)
if($lastHeading !== $row['Heading']) {
echo $row['Heading'];
$lastHeading = $row['Heading'];
}
else {
//change this output to fit your output format
echo "";
}
//check if there is a new category (if so, print it and update $lastCagetory
if($lastCategory !== $row['Category']) {
echo $row['Category'];
$lastCategory = $row['Category'];
}
else {
//change this output to fit your output format
echo "";
}
//add the test name
echo ($row['Tests']);
}
您应该更新标记/输出以适合您的实际布局/所需的html。它可能是一个表,它可能是其他类型,但我希望这个概念是可以理解的。