0

嗨,我有一个表,我希望在其中搜索以前的记录,我有带搜索选项的选择框这里是代码

    if (isset($_REQUEST['searchtype']) && isset($_REQUEST['period']))
    {
    if ($_REQUEST['searchtype'] == "All")
        {
        $period = "All";
        }
    elseif ($_REQUEST['searchtype'] == "Last24hours")
        {
        $period = date('Y-m-d H:i:s')-86400;
        }
    elseif ($_REQUEST['searchtype'] == "Last10days")
        {
        $period = date('Y-m-d H:i:s')-864000;
        }
    elseif ($_REQUEST['searchtype'] == "LastHour")
        {
        $period = date('Y-m-d H:i:s')-3600;
        }
    elseif ($_REQUEST['searchtype'] == "Lastweek")
        {
        $period = date('Y-m-d H:i:s')-604800;
        }
    elseif ($_REQUEST['searchtype'] == "LastMonth")
        {
        $period = date('Y-m-d H:i:s')-2592000;
        }
      else
        {
        $period = $_REQUEST['searchtype'];
        }

我该怎么做...

4

2 回答 2

0

像这样使用$period = time() - 86400;

于 2013-03-07T15:14:30.413 回答
0
if (isset($_REQUEST['searchtype']) && isset($_REQUEST['period']))
{
    $searchtype = $_REQUEST['searchtype'];
    switch($searchtype)
    {
        case 'Last24hours':
            $period = time() - 86400;
        break;
        case 'Last10days':
            $period = time() - 864000;
        break;
        case 'LastHour':
            $period = time() - 3600;
        break;
        case 'Lastweek':
            $period = time() - 604800;
        break;
        case 'LastMonth':
            $period = time() - 2592000;
        break;
        case 'ALL':
        default:
            $period = "All";
    }

    $sql_by_time = ($period != "All") ? " AND time > $period" : "";
}

用你在你的SELECT * FROM

SELECT * FROM YOUR_TABLE
WHERE YOUR_WHERE
$sql_by_time
于 2013-03-07T15:37:51.390 回答