简体   繁体   中英

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

I need to filter data from joining multiple table and mapping current date with the date range present in the table using PHP and MySQL . I am explaining the scenario below.

$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"}]

I have the above input array whose value should compare with the multiple table.

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

The second table is given below.

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

Here I need to join two table as per the array value in loop and fetch the additional data into array. In array each row has value reg_no which will match with column of regn_no table db_application and the column value of exam_code and Institute_code column value should match with second table ie-db_app exam_code and Institute_code column value. another condition is the current date should present within start_date and end_date and finally the using these condition the value will be filtered from the array. I need to query to filter from array using these table.

For what it's worth, a sample dataset like the following does nothing to undermine the intent of your question, and I find it much easier to read...

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

Now, we can see that you have comma-separated values in your db_app table. This is a mistake. Move these out into a separate, normalised, table.

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