PHP怎麼按日期查詢

來源:互聯網
上載者:User
PHP如何按日期查詢
MYSQL裡欄位addtime為時間戳記
我現在須要這樣查詢
xx.php?u=20130328&page=1 &page=這個用來分頁
這樣查詢20130328或20130329這一天資料


include "../include/song.inc.php";
$key = $_GET['u'];
if($_GET["page"]){
$page=$_GET["page"];#擷取要顯示的頁碼
}else{
$page=1;#沒有參數傳入時,顯示第一頁
}
$col=20;#每頁顯示記錄條數
$p=($page-1)*$col;
$runSql = mysql_query("select * from cmsdj_song where uid = '$key' order by id desc limit ".$p.",".$col."");
while($row = mysql_fetch_array($runSql))
{
//下面這些是調用值
$sid=$row['id'];
$suid=$row['uid'];
$supip=$row['upip'];
$name=$row['name'];
$sname=substr($name,0,30);
$sfile=$row['file'];
$surl=$row['url'];
$swjdx=$row['wjdx'];
$stime=date('Y-m-d H:i:s',$row['addtime']);
//$b64file=base64_encode($surl);
?>













'> '> '> '>

}
?>
$col=20;#每頁顯示記錄條數
$count=mysql_query("select id from cmsdj_song where uid like '%$key%'");#取得記錄總條數
$num = mysql_num_rows($count)/$col;#計算頁數
$nnx = mysql_num_rows($count);#計算頁數
$num=ceil($num);#無條件小數進位確定總頁數
mysql_close();
?>


------解決方案--------------------
FROM_UNIXTIME() UNIX時間戳記轉換為日期
UNIX_TIMESTAMP() 日期轉換為UNIX時間戳記
------解決方案--------------------

$u = $_GET['u'];

$starttime = strtotime($u.'000000');
$endtime = strtotime($u.'235959');

$runSql = mysql_query("select * from cmsdj_song where addtime > '$starttime' and addtime<'$endtime' order by id desc limit ".$p.",".$col."");
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.