簡體   English   中英

顯示具有特定值的類別下的子類別

[英]display sub-category under category with certain value

我有一個表“測試”。

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”,如其所示。 任何幫助將不勝感激。

一個簡單的方法是有一個這樣的查詢:

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。 它可能是一張桌子,也可能是其他類型,但我希望這個概念是可以理解的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM