简体   繁体   English

如何在php MySQL中获取以前的日期数据

[英]How to fetch previous date data in php mysql

在此处输入图片说明

I am working on stock project in PHP.Currently while searching according date it is showing data according searching date which is good.But those date which is not avail in database ,it is showing blank,while i need prevous date data.(Like if i enter 25.12.2015,in the result it should show previous date data like 23.12.2015 in this case.) 我正在用PHP进行股票项目。当前在按日期搜索时,它正在根据搜索日期显示数据,这很好。但是那些在数据库中不可用的日期却显示为空白,而我需要以前的日期数据。我输入25.12.2015,在这种情况下,结果应显示以前的日期数据,例如2015年12月23日。)

my html code is: 我的html代码是:

<form action="dateview.php" method="post">
     <table width="60%" border="2" bordercolor="green">
     <tr>
     <td>DATE</td>
     <td>
         <input type="date" name="date">
     </td>
     <td colspan="2">
         <center><input type="submit" value="search"/></center>
     </td>
     </table>   
</form> 

my php code is: 我的PHP代码是:

<?php
      if($qw="select * from details where date='$date'"){
      $qq = mysqli_query($con,$qw);
      while($r=mysqli_fetch_array($qq,MYSQLI_ASSOC))
      {
        ?>
        <tr>
        <td><?php echo $r['itemname']; ?></td>
        <td><?php echo $r['deposit']; ?></td><td><?php echo $r['withdraw']; ?></td>
        <td><?php echo $r['total']; ?></td>
        <td><?php echo $r['approvedby']; ?></td>
        <td><?php echo $r['receivedby']; ?></td>
        <td><?php echo $r['givenby']; ?></td>
        <td><?php echo $r['receivedto']; ?></td>
        </tr>
<?php } ?>

You might use something like this 您可能会使用类似这样的东西

date('Y-m-d', strtotime("23.12.2015")); // o/p: 2015-12-23

Where 'Ymd' format you stored in DB. 您将“ Ymd”格式存储在数据库中的位置。

Refer date format here 在此参考日期格式

只需调整您的SELECT查询:

SELECT * FROM details WHERE date <= 'your-date-here' ORDER BY date DESC LIMIT 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM