PHP code to match column values using if esle
I have two tables ...
holidaymaster
id holidaydate cityid
1 18-04-2015 9
mailing table
id coupondate cityname customer
1 15-04-2015 9 A
2 16-04-2015 9 B
3 17-04-2015 9 C
4 19-04-2015 9 D
I need to get data from both tables by joining them ...
and need to check if holiday is not empty in holidaymaster ... then echo null against this date else echo 1.
Expected Result
customer coupondate Type
A 15-04-2015 1
B 16-04-2015 1
C 17-04-2015 1
NULL NULL NULL
D 19-04-2015 1
In abov ex - 18-04-2015 is available in holidaymaster so I need to display zero on this ... display.
plz help me how to join this table and match rows ...
and if connection is not possible, then how to combine with two different queries using if else.
below is my code.
I am trying to run 2 diff request.
$data = $database->getRows("SELECT RE.* FROM receipt_entry RE LEFT JOIN city_master CM ON RE.city_name = CM.id WHERE CM.cityname = :cityname
AND str_to_date(RE.coupondate,'%d-%m-%Y') BETWEEN :fromdate AND :todate ORDER BY STR_TO_DATE(RE.coupondate,'%d-%m-%Y') ASC",
array(':fromdate'=>$formdate_sql,':todate'=>$todate_sql,':cityname'=>$cityname));
$holiday = $database->getRows("SELECT HM.holidaydate from holidaymaster HM LEFT JOIN city_master CM ON HM.cityid = CM.id WHERE CM.cityname = :cityname
AND str_to_date(HM.holidaydate,'%d-%m-%Y') BETWEEN :fromdate AND :todate",array(':fromdate'=>$formdate_sql,':todate'=>$todate_sql,':cityname'=>$cityname));
<?php if (is_array($data)) { foreach($data as $row) { ?>
<?php foreach($holiday as $row1) { ?>
<?php if($row['coupondate'] == $row1['holidaydate']) { ?>
<td>-</td>
<?php } else { ?>
<td>1</td>
<?php } ?>
<?php } } ?>
+3
source to share