使用mysql查询选择记录小于当前日期?

时间:2011-06-01 06:44:42

标签: mysql datetime date

我想从表中选择arrival_date小于当前日期的记录(arrival_date是表honymoon_enquries表中的字段名称)日期我的代码是

<?php
error_reporting(E_ALL ^ E_NOTICE);
    session_start();

    require_once("config.php");

    if($_SESSION["valid"] != true) 
    {   
        header("Location: index.php");

        exit(0);    
    }   

    if(count($_REQUEST['users']) > 0)   
    {
        //print_r($_REQUEST['users']);     
        $DeleteList = implode(",",$_REQUEST['users']);

        $UpdateQuery = " UPDATE honymoon_enquries SET deleted = '1' WHERE id IN (".$DeleteList.") ";

        mysql_query($UpdateQuery);    
    }

    if(isset($_REQUEST['pageid']) && $_REQUEST['pageid'] > 1)    
    {    
        $start = ($_REQUEST['pageid'] - 1) * 10;

        $pageidprev = $_REQUEST['pageid'] - 1;

        $pageidnext = $_REQUEST['pageid'] + 1;    
    }    
    else  
    {    
        $start = 0;

        $pageidprev = 1;

        $pageidnext = 2;   
    }

    $countquery = "SELECT count(*) AS counter FROM honymoon_enquries WHERE status='1' AND deleted = '0' ";


    $countres=mysql_query($countquery);

$count = mysql_fetch_array($countres);

    //print_r($count);

     $query = "select * from honymoon_enquries WHERE status='1' AND deleted = '0' order by arrival_date DESC LIMIT ".$start.",10 ";  // i want update this query

$res=mysql_query($query);

if(mysql_num_rows($res) < 10)    
{   
        $pageidnext = $pageidnext-1;    
}    

if(($start+10) > $count['counter'])   
{  
    $end = $count['counter']; 
}  
else   
{ 
    $end = $start+10;   
}

$main .= "  
            <script>



            function DeleteUser()
            {
                if(confirm('Are you sure want to delete this contact?'))
                {
                    document.frm.submit();
                }
            }

            </script>

            <div class=heading>Manage Subscribers</div>

            $msg

            <form name='frm' method='post' action='users.php'>

            <table width=100%>

            <tr>

            <td colspan='6'><strong>Showing ".($start+1)." to ".$end." of ".$count['counter']."</strong></td>

            </tr>

            <tr>

            <td colspan='6' align='left'>

            <a href='users.php?pageid=".$pageidprev."'>Prev</a>&nbsp;

            <a href='users.php?pageid=".$pageidnext."'>Next</a>

            </td>

            </tr>

            <tr>

            <td><strong>Check</strong></td>

            <td><strong>Name</strong></td>

            <td><strong>Email</strong></td>

            <td><strong>Phone</strong></td>

            <td><strong>Arival Date</strong></td>

            <td><strong>Action</strong></td>

            </tr>

            ";



            while ($resresult=mysql_fetch_array($res))

        {
            //print_r($resresult);

            $main .= "

            <tr>

            <td><input type='checkbox' name='users[]' value='".$resresult['id']."' ></td>

            <td align='left'>".$resresult['client_name']."</td>

            <td align='left' >".$resresult['client_email']."</td>

            <td align='left' >".$resresult['client_phone']."</td>

            <td align='center' >".$resresult['arrival_date']."</td>

            <td align='center' ><a href='viewuser.php?pageid=".$resresult['id']."'>View User</a></td>

            </tr>

             ";
        }

        $main .= "<tr>

            <td colspan='6' align='left'>

            <a href='javascript:void(0);' onclick='DeleteUser();'>Delete</a>&nbsp;

            </td>

            </tr>";

            $main .= "

            </table>

            </form>

             ";

    $yescallme=1;

    $page = "users";

    require_once("includes/template.php");
    ?>

谢谢。

1 个答案:

答案 0 :(得分:5)

试试这个:

SELECT * FROM honymoon_enquries
WHERE arrival_date < NOW()