donglian4770 2015-05-21 13:09
浏览 28

php代码使用if else循环1 ...直到最后一个日期

table receipt

 coupondate  receipt
 02-05-2015    5
 02-09-2015    5

i am selecting min coupondate and max coupondate from table...

below is my query..

SELECT RE.*,min(RE.coupondate) As mindate,max(RE.coupondate) As Maxdate FROM receipt_entry RE  GROUP BY RE.receipt_no

Next i used fromdate and todate textbox in my form.

if user enter fromdate = 01-05-2015 and todate = 31-05-2015..then i am display all days between this two dates like below example....

01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18  ......upto ....31

i used below code to display all days between two 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 } ?>

Now what i need is ...

I need to print 1 starts from $row(mindate) and print continously upto last day.that is 31

Expected output is

01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 ....31
    1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1      1

i try below code to print 1 which starts from mindate and end on 31.

but my code only display 1 below mindate..thats it...

<?php  if (is_array($data)) { foreach($data as $row)    {   ?>
<tbody>
    <tr>                    
        <td><?php echo htmlspecialchars($row['customer_name']); ?></td>
        <td><?php echo htmlspecialchars($row['startingdate']); ?></td>
        <td><?php echo htmlspecialchars($row['coupondate']); ?></td>

        <?php for ($x = $start; $x <= $end; $x++) { ?>  

            <?php if($row['mindate']== $x) { ?> 
            <td>1</td>          
            <?php } else {?>
            <td>-</td>
            <?php } ?>  

        <?php } ?>  
    </tr>
    <?php } }?>

I am getting below output..

01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 ....31
-   1  -  -  -  -   -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -      -
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
    • ¥15 基于52单片机的酒精浓度检测系统加继电器和sim800
    • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
    • ¥15 Centos / PETSc / PETGEM
    • ¥15 centos7.9 IPv6端口telnet和端口监控问题
    • ¥120 计算机网络的新校区组网设计
    • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 海浪数据 南海地区海况数据,波浪数据
    • ¥20 软件测试决策法疑问求解答