簡體   English   中英

如何使用Mysql和PHP從具有當前日期的多個表映射日期范圍中篩選數據

[英]How to filter data from multiple table mapping date range with current date using Mysql and PHP

我需要使用PHP and MySQL從聯接多個表中過濾數據,並映射當前日期與表中存在的日期范圍。 我在解釋下面的情況。

$inputArr=array(array("reg_no"=>"AD17323","college_roll_no"=>"AD1700323","institute_code"=>"AD","full_name"=>"RAJU MALLICK"),array("reg_no"=>"AD17298","college_roll_no"=>"AD1700298","institute_code"=>"AD","full_name"=>"BISWARAJ NAYAK"));
echo json_encode($inputArr);

//[{"reg_no":"AD17323","college_roll_no":"AD1700323","institute_code":"AD","full_name":"RAJU MALLICK"},{"reg_no":"AD17298","college_roll_no":"AD1700298","institute_code":"AD","full_name":"BISWARAJ NAYAK"}]

我有上面的輸入數組,其值應該與多重表進行比較。

db_application:

id      regn_no        exam_code                            Institute_code                            institute_code

1        AD17323     01b1bf82-f206-11e7-a317-005056991fed         AD

2        AD17298     02a1c160-f206-11e7-a317-005056991fed         AD

下面給出第二個表。

db_app:

id       start_date             end_date            exam_code                                       Institute_code         

    1         2018-05-14            2018-05-14           01b1bf82-f206-11e7-a317-005056991fed              AD,BD,MN

在這里,我需要根據循環中的數組值連接兩個表,並將其他數據提取到數組中。 在陣列中的每個行具有值reg_no其將與列匹配regn_nodb_application和的列值exam_code and Institute_code列值應該與第二表匹配ie-db_app exam_code and Institute_code列值。 另一個條件是當前日期應出現在start_date and end_date ,最后使用這些條件將從數組中過濾出該值。 我需要查詢以使用這些表從數組中進行過濾。

值得一提的是,像下面這樣的樣本數據集並不能破壞您提出問題的意圖,而且我發現它更容易閱讀...

db_application:

id regn_no exam_code institute_code 
 1 AD17323 01b1bf82  AD
 2 AD17298 02a1c160  AD

db_app:

id start_date end_date   exam_code institute_code         
 1 2018-05-14 2018-05-14 01b1bf82  AD,BD,MN

現在,我們可以看到db_app表中有逗號分隔的值。 這是個錯誤。 將它們移到單獨的標准化表中。

暫無
暫無

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

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