简体   繁体   中英

how can I filter by date in mysql with the same data entry using php?

I have this problem on my project this is my code:

<?php
if (isset($_POST['search']))
{   
    $a = isset($_POST['from'])?$_POST['from']:"";
    $b = isset($_POST['to'])?$_POST['to']:"";
    $c = isset($_POST['status'])?$_POST['status']:"";

    if($c=='Delivered' || $c=='Cancelled'){
        $rest = mysql_query("SELECT * FROM delivered WHERE dateord BETWEEN '$a' and '$b' AND stats = '$c' order by dateord DESC");
        while($row1 = mysql_fetch_assoc($rest)){
?>
        <tr align="center" bgcolor="#00FFCC" style="font-size:10px">
            <td><?php echo $row1['customer']; ?></td>
            <td><?php echo $row1['itemname'];?></td>
            <td><?php echo number_format($row1['unitP']); ?></td>
            <td><?php echo $row1['quant']; ?></td>
            <td><?php echo number_format($row1['totalP']); ?></td>
            <td><?php echo $row1['dateord']; ?></td>
            <td><?php echo $row1['stats']; ?></td>
            <td><?php echo $row1['tracknumb']; ?></td>
        </tr>
<?php } ?>

my problem is if I input an entry of the same date it doesn't show. example I would like to input from: 2013-11-06 to: 2013-11-06 so I can print data just on that date. but its not working.. what should i do? I'm very noob at this still learning..thanks!

这样的事情可能会包括时间部分

SELECT * FROM delivered WHERE dateord >='$a' and dateord<date_add('$b',interval 1 day)

Try like this if dateord is a date or timestamp field.

SELECT * FROM delivered WHERE dateord 
BETWEEN '".$a."' and '".$b."' AND stats = '".$c."' 
ORDER BY dateord DESC

Try this:
$rest = mysql_query("SELECT * FROM delivered WHERE dateord BETWEEN '".$a."' and '".$b."' AND stats = '".$c."' order by dateord DESC");

尝试

"SELECT * FROM delivered WHERE dateord BETWEEN date('".$a."') and date('".$b."' AND stats = '".$c."' order by dateord DESC"

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.

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