2016-06-27 15 views
2

enter image description here如何獲取在PHP的MySQL以前的最新數據

我在PHP.Currently而尋找根據最新的工作對股票項目是根據其是好。不過那些未利用日期檢索日期顯示數據(如果我輸入25.12.2015,結果它應該顯示之前的日期數據,如23.12.2015在這種情況下)。

我的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> 

我的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 } ?> 
+0

'25.12.2015'或'23.12.2015'不是一個有效的格式,無論是數據保存爲'unix時間戳'或'datetime'。之後,數據操作查詢可能會發生。現在您需要[格式](https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-format)提前預約。 – Xorifelse

+0

將條件改爲'where date <='$ date'「',這會給你以前的日期數據包括你通過的日期的數據 –

+0

謝謝Code-Monk.Its工作。 – saurabh

回答

0

你可能會使用類似這樣

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

在哪裏 'Y-M-d' 的格式,你保存在數據庫中。

請參閱日期格式here

0

只需調整您的SELECT查詢:

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