Php code to match column date to database and display client data

Table Name - Check Table

The data are presented in the table as shown below.

 coupondate    customer      
 02-04-2015     A         
 02-05-2015     A         
 02-06-2015     A         
 02-07-2015     A        
 02-08-2015     A       
 02-09-2015     A  

 05-04-2015     B         
 05-05-2015     B         
 05-06-2015     B         
 05-07-2015     B        
 05-08-2015     B       
 05-09-2015     B       

In the above table, client A is present from 02-04-2015 to 02-09-2015, so I need to display p for client A from 02-04 to 02-09.

In the above table, client B is present from 05-04-2015 to 05-09-2015, so I need to display p on client B from 05-04 to 05-09, as wise ...

Expected Result

Days  02-04 03-04 04-04 05-04 06-04 07-04 08-04 09-04 10-04 11-04 12-04 13-04 14-04 -15-04.....like wise upto 02-09
 A      P     P     P     P     P      P     P    P    P     P      P    .......like wise upto 15-09   
 B                       P      P      P     P    P    P     P      like wis....upto 05-09    

below is my code ...

<?php
if($_POST && isset($_POST['Submit']))
{       
        if($_POST['fromdate']!='' && $_POST['todate']!='')
        {
                $fromdate = $_POST['fromdate'];
                $todate = $_POST['todate'];
                $cityname = $_SESSION['Auth']['city'];
                $formdate_r = DateTime::createFromFormat('d-m-Y', $fromdate);
                $todate_r = DateTime::createFromFormat('d-m-Y', $todate);
                $formdate_sql = $formdate_r->format("Y-m-d");
                $todate_sql = $todate_r->format("Y-m-d");

                $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));

        }
}
?>


<?php
$startdate = $_POST['fromdate'];
$enddate = $_POST['todate'];
$start = date('d', strtotime($startdate));
$end=date('d', strtotime($enddate));
?>  
<?php   for ($x = $start; $x <= $end; $x++) { ?>
    <th width="58%"><?php echo $x; ?></th>
    <?php } ?>

The code below is used to verify compliance with the days.

this code works fine, but only displays one P at a consistent date, but I need to display p against all days.

<?php  if (is_array($data)) { foreach($data as $row)    {   ?>
    <?php if($row['coupondate'] == $x) { ?>
            <td>P</td>
            <?php }  else { ?>
            <td>--</td>
            <?php } ?>  
<?php } }?>
+4
source share
1 answer

if($row['coupondate'] == $x), $row['coupondate'] - dd-mm-YYYY, $x - . :

if(date('d', strtotime($row['coupondate']) == $x)

@honza-haering .

0

All Articles