如何获得前一天(连续) [英] How to get the previous day (continous)

查看:75
本文介绍了如何获得前一天(连续)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我只希望在按下按钮时获得前一天或最后一天的信息,并且它会在最后一天(星期六)显示所有信息,如果再次单击该按钮,它会显示最后一天的信息(星期五),如果我再次点击它(星期四),谢谢帮助我们的朋友们



编辑:

strong> generate_attendance.php

  if(isset($ _ POST ['submit1'])){
$ prev_date = date('Y / m / d',strtotime( - 1 days));


$ query = mysqli_query($ dbcon,select * from attendance where date_added'$ prev_date')或die(mysql_error());
while($ row = mysqli_fetch_array($ query)){

$ attendance_id = $ row ['attendance_id'];


?>

< tr>
< td><?php echo $ row ['lastname']。','。$ row ['firstname']; ?>< / TD>
< td><?php echo $ row ['course']; ?>< / TD>
< td><?php echo $ row ['type']; ?>< / TD>
< td><?php echo $ row ['year_level']; ?>< / TD> < td><?php echo $ row ['date_added']; ?< / TD>
< / tr>
<?php

< div class =controls>


generate_attendance.php(完整代码) $ b

 < div class =container> 
< div class =margin-top>
< div class =row>
< div class =alert alert-info>
< button type =buttonclass =closedata-dismiss =alert>& times;< / button>
< strong>< i class =icon-user icon-large>< / i>& nbsp;考勤报告< / strong>
< / div>

< div class =span12>
< center class =title>
< h1>考勤列表< / h1>
< / center>

< div class =pull-right>
< a href =onclick =window.print()class =btn btn-info>< i class =icon-print icon-large>< / i>打印与LT; / A>
< / div>
< form method =post>
< div class =span3>



< div class =control-group>
< label class =control-labelfor =inputEmail><! - 考勤报告 - >< / label>
< div class =controls>
< label class =control-labelfor =inputEmail>从< / label>
< div class =controls>
< input type =datename =from_dateid =date1alt =dateclass =IP_calendartitle =d / m / Y>
< / div>
< / div>
< / div>
< div class =control-group>
< label class =control-labelfor =inputEmail>至日期< / label>
< div class =controls>
< input type =datename =to_dateid =date2alt =dateclass =IP_calendartitle =d / m / Y>
<! - < input type =textclass =w8em format -dmy highlight-days-67 range-low-todayname =due_dateid =sdmaxlength =10 style =border:3px double #CCCCCC;需要/> - >
< / div>
< / div>
< div class =control-group>
< div class =controls>


解决方案

可能传递查询参数,表示有多少日期它应该减去,所以网址如下所示:

  yourphpscript.php? days = 3 

然后你可以在php中获取它,并更改日期构建:

  $ days = $ _GET [days]; 
if(!isset($ days)){
$ days = 1;
}
$ days = intval($ days);
$ prev_date = date('Y / m / d',strtotime( - 。$ days。days));

所以现在唯一缺少的就是改变下一个请求的url,像这样:

 < form href =?days =<?php echo $ days + 1;?> > 


Hello guys I want to get the information of previous date or last day only when I press the button and it will display the all information last day (saturday) and if I click the button again it will shows information of last last day (friday) and if I click it again (thursday) thanks for helping me guys

EDITED:

generate_attendance.php

if(isset($_POST['submit1'])){
                                 $prev_date= date('Y/m/d',strtotime("-1 days"));


                                    $query=mysqli_query($dbcon,"select * from attendance where date_added '$prev_date'")or die(mysql_error());
                                    while($row=mysqli_fetch_array($query)){

                                    $attendance_id=$row['attendance_id'];


                                    ?>

                                    <tr>
                                       <td><?php echo $row['lastname'].', '.$row['firstname']; ?></td>
                                       <td><?php echo $row['course']; ?></td>
                                       <td><?php echo $row['type']; ?></td>
                                       <td><?php echo $row['year_level']; ?></td>                                           <td><?php echo $row['date_added']; ?</td>                                
                                    </tr>
                                    <?php

            <div class="controls">


                            <button name="submit1" type="submit1" class="btn btn-success"><i class="icon-plus-sign icon-large"></i> Previous Day</button>
                </div>
            </div>

generate_attendance.php (full code)

<div class="container">
    <div class="margin-top">
        <div class="row">   
                            <div class="alert alert-info">
                                <button type="button" class="close" data-dismiss="alert">&times;</button>
                                <strong><i class="icon-user icon-large"></i>&nbsp;Attendance Report</strong>
                            </div>

    <div class="span12">    
       <center class="title">
                    <h1>Attendance List</h1>
                    </center>

                            <div class="pull-right">
                            <a href="" onclick="window.print()" class="btn btn-info"><i class="icon-print icon-large"></i> Print</a>
                            </div>  
    <form method="post">
    <div class="span3">



                                        <div class="control-group">
            <label class="control-label" for="inputEmail"><!-- Attendance Report --></label>
            <div class="controls">
            <label class="control-label" for="inputEmail">From</label>
                <div class="controls">
                <input type="date" name="from_date" id="date1" alt="date" class="IP_calendar" title="d/m/Y">
                </div>
            </div>
        </div>
            <div class="control-group"> 
                <label class="control-label" for="inputEmail">To Date</label>
                <div class="controls">
                    <input type="date" name="to_date" id="date2" alt="date" class="IP_calendar" title="d/m/Y">
            <!--    <input type="text"  class="w8em format-d-m-y highlight-days-67 range-low-today" name="due_date" id="sd" maxlength="10" style="border: 3px double #CCCCCC;" required/> -->
                </div>
            </div>
            <div class="control-group"> 
                <div class="controls">

                            <button name="submit" type="submit" class="btn btn-success"><i class="icon-plus-sign icon-large"></i> Search</button>
                </div>
            </div>
            <div class="controls">


                            <button name="submit1" type="submit1" class="btn btn-success"><i class="icon-minus-sign icon-large"></i> Previous Day</button>
                </div>
            </div>



            <div class="span8">
                    <div class="alert alert-success"><strong>Attendance Report</strong></div>
                        <table cellpadding="0" cellspacing="0" border="0" class="table" id="example">

                            <thead>
                                <tr>



                                        <th>Name</th>
                                        <th>Program Code</th>
                                        <th>Type</th>
                                        <th>Year level</th>
                                        <th>Date Log-in</th>

                                </tr>
                            </thead>
                           <tbody>
                                <?php
                    if(isset($_POST['submit'])){
                                    $from_date=$_POST['from_date'];
                                    $to_date=$_POST['to_date'];

                                    $query=mysqli_query($dbcon,"select * from attendance where date_added between '$from_date' and '$to_date'")or die(mysql_error());
                                    while($row=mysqli_fetch_array($query)){

                                    $attendance_id=$row['attendance_id'];


                                    ?>

                                    <tr>
                                       <td><?php echo $row['lastname'].', '.$row['firstname']; ?></td>
                                       <td><?php echo $row['course']; ?></td>
                                       <td><?php echo $row['type']; ?></td>
                                       <td><?php echo $row['year_level']; ?></td>
                                       <td><?php echo $row['date_added']; ?></td>

                                    </tr>
                                    <?php
                                    }}
?>

       <?php


                    if(isset($_POST['submit1'])){



                                      $prev_date= date('Y/m/d',strtotime("-1 days"));

                                    $query=mysqli_query($dbcon,"select * from attendance where date_added between '$curr_date' and '$prev_date'")or die(mysql_error());
                                    while($row=mysqli_fetch_array($query)){

                                    $attendance_id=$row['attendance_id'];


                                    ?>

                                    <tr>
                                       <td><?php echo $row['lastname'].', '.$row['firstname']; ?></td>
                                       <td><?php echo $row['course']; ?></td>
                                       <td><?php echo $row['type']; ?></td>
                                       <td><?php echo $row['year_level']; ?></td>
                                       <td><?php echo $row['date_added']; ?></td>

                                    </tr>
                                    <?php
                                    }}
                                    ?>

                            </tbody>
                        </table>

            </form>
        </div>      
        </div>      

        </div>
    </div>
</div>

解决方案

Probably pass a query parameter, that indicates how many dates it should subtract, so the url looks like this:

yourphpscript.php? days = 3

Then you can get that in the php, and change the date building:

$days = $_GET["days"];
if(!isset($days)){
 $days = 1;
}
$days = intval($days);
$prev_date= date('Y/m/d',strtotime("-".$days." days"));

So now the only thing thats missing, is to change the url of the next request, which would look like this:

<form href="?days=<?php echo $days+1;?>" >

这篇关于如何获得前一天(连续)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆