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.)
my html code is:
<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
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.
Refer date format here
只需调整您的SELECT
查询:
SELECT * FROM details WHERE date <= 'your-date-here' ORDER BY date DESC LIMIT 1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.