-4

Tablename - Receipt

   coupondate    name      recno
   15-04-2015     A          1
   15-05-2015     A          1
   15-06-2015     A          1
   15-07-2015     A          1
   15-08-2015     A          1
   15-09-2015     A          1      

FOR EX - Expected output

Days  15-04 16-04 17-04 18-04 19-04 20-04 21-04.....like wise upto 15-09
 A     P     P     P     P     P      P     P                        P  

to display all days within selected date.

<?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 } ?>

below code to display P Else NULL

<?php if($row['coupondate'] == $x) { ?>
        <td>P</td>
        <?php }  else { ?>
        <td>NULL</td>

Now i cannot understand here how to display P if coupondate matched with $x date..

for ex - coupondate starts from 15-04 and end on 15-09 ok..

now i need to display P below to this customer from 15-04 upto 15-09

ankit ingle
  • 213
  • 1
  • 5
  • 10
  • 3
    Please, post an sqlfiddle link with sample data and a query, you tried to solve the problem – user4035 May 18 '15 at 11:18
  • Note that dates in SQL adhere to a specific format, but beyond that this is just a simple question about data display. You would handle that in your application level code (php), with a simple loop. There's no point posting a sqlfiddle for this. It's not an sql problem. – Strawberry May 18 '15 at 11:20
  • sql fiddle link..http://sqlfiddle.com/#!9/dcb16/1 – ankit ingle May 18 '15 at 11:28
  • i know how to generate days but the problem i need to get min and max coupondate in query without any condition and also need to display P below all days.. – ankit ingle May 18 '15 at 11:42
  • plz see my edited question and suggest proper solution as i want...plz... – ankit ingle May 18 '15 at 12:37

1 Answers1

0

See this:

generate days from date range

Community
  • 1
  • 1
Pathik Vejani
  • 4,263
  • 8
  • 57
  • 98