duanmi1900 2015-07-23 11:39
浏览 89
已采纳

如何每周获取数据。 只到星期一到下个星期天

I have coded a program in which i can get data of last 7 days. But i want that my data should be visible of Last week and Week starts from Monday and Ends at Sunday. Then on Monday next Week starts. So i want if today is Wednesday and If i click on week report. Then it should get data till last Monday only . Like (Wednesday, Tuesday, Monday) But My System Counts complete 7 Days. Here are my Codes.

date_default_timezone_set("EST");
$wdate = date('Y-m-d');
$wdate_to = $wdate;
$wdate_to = strtotime("-7 days", strtotime($wdate_to)); //-7 days for last week. -30 for last week
$wdate_to = date("Y-m-d", $wdate_to);


$wget_req = "SELECT * FROM `requests` WHERE `assign_date` between '$wdate_to' AND '$wdate' AND `assigned`=1";

$result = mysqli_query($dbc, $wget_req);

while ($res = mysqli_fetch_assoc($result)){
    $driver_id = $res['assigned_driver_id'];
    $req_id = $res['req_id'];
    $req_title = $res['request_title'];
    $req_price = $res['price'];
    $req_time = $res['request_time'];
    $req_date = $res['assign_date'];
    $req_desc = $res['req_desc'];
    $assigned = $res['assigned'];
    $status = $res['req_status'];
    $driver = $res['driver_name'];
$get_record = "SELECT * FROM `members` WHERE `Memberid`='$driver_id' AND `u_level`=3";
$res = mysqli_query($dbc, $get_record);
while($row = mysqli_fetch_assoc($res)){

    $status = $row['u_status'];
}
?>

                                        <tr class="gradeA">
                                            <td><b><?php echo $driver ;?></b></td>
                                            <td><?php echo $driver_id ;?></td>
                                            <td><?php echo $req_date ;?></td>
                                            <td><b><?php echo $wdate_to;?></b> &#8596; <b><?php echo $wdate ;?></b></td>
                                            <td class="center"><?php if($status == 1){echo '<a href="#" class="btn btn-danger btn-sm">Driver is not working. Deactivated</a>';}else if($status == 0){echo '<a href="#" class="btn btn-success btn-sm">Driver is Active. Working</a>';}?></td>
                                            <td class="center"> <a href="weekly_report.php?driver_id=<?php echo $driver_id ;?>" class="btn btn-primary btn-sm">View Report</a>
 </td>
                                        </tr>

<?php } ?> 

I hope to get help soon

  • 写回答

4条回答 默认 最新

  • dqmdlo9674 2015-07-23 11:51
    关注

    Try this, it may help you

    <?php
    date_default_timezone_set("EST");
    $wdate = date('Y-m-d',strtotime('monday this week'));
    $wdate_to = $wdate;
    $wdate_to = strtotime("-7 days", strtotime($wdate_to)); //-7 days for last week. -30 for last week
    $wdate_to = date("Y-m-d", $wdate_to);
    
    
    $wget_req = "SELECT * FROM `requests` WHERE `assign_date` between '$wdate_to' AND '$wdate' AND `assigned`=1";
    
    $result = mysqli_query($dbc, $wget_req);
    
    while ($res = mysqli_fetch_assoc($result)){
        $driver_id = $res['assigned_driver_id'];
        $req_id = $res['req_id'];
        $req_title = $res['request_title'];
        $req_price = $res['price'];
        $req_time = $res['request_time'];
        $req_date = $res['assign_date'];
        $req_desc = $res['req_desc'];
        $assigned = $res['assigned'];
        $status = $res['req_status'];
        $driver = $res['driver_name'];
    $get_record = "SELECT * FROM `members` WHERE `Memberid`='$driver_id' AND `u_level`=3";
    $res = mysqli_query($dbc, $get_record);
    while($row = mysqli_fetch_assoc($res)){
    
        $status = $row['u_status'];
    }
    ?>
    
                                            <tr class="gradeA">
                                                <td><b><?php echo $driver ;?></b></td>
                                                <td><?php echo $driver_id ;?></td>
                                                <td><?php echo $req_date ;?></td>
                                                <td><b><?php echo $wdate_to;?></b> &#8596; <b><?php echo $wdate ;?></b></td>
                                                <td class="center"><?php if($status == 1){echo '<a href="#" class="btn btn-danger btn-sm">Driver is not working. Deactivated</a>';}else if($status == 0){echo '<a href="#" class="btn btn-success btn-sm">Driver is Active. Working</a>';}?></td>
                                                <td class="center"> <a href="weekly_report.php?driver_id=<?php echo $driver_id ;?>" class="btn btn-primary btn-sm">View Report</a>
     </td>
                                            </tr>
    
    <?php } ?> 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 数学建模数学建模少ai
  • ¥15 有没有cst丛书18算例21
  • ¥15 如何把LibreOffice添加到自定义层中
  • ¥35 这个的负序网络和零序网络怎么画?(答疑)
  • ¥200 基于同花顺supermind的量化策略脚本编辑
  • ¥20 Html备忘录页面制作
  • ¥15 黄永刚的晶体塑性子程序中输入的材料参数里的晶体取向参数是什么形式的?
  • ¥20 数学建模来解决我这个问题
  • ¥15 计算机网络ip分片偏移量计算头部是-20还是-40呀
  • ¥15 stc15f2k60s2单片机关于流水灯,时钟,定时器,矩阵键盘等方面的综合问题