Home > Backend Development > PHP Tutorial > PHP怎么按日期查询

PHP怎么按日期查询

WBOY
Release: 2016-06-13 12:50:19
Original
1289 people have browsed it

PHP如何按日期查询
MYSQL里字段addtime为时间戳
我现在须要这样查询
xx.php?u=20130328&page=1 &page=这个用来分页
 这样查询20130328或20130329这一天数据


<?php<br />
include "../include/song.inc.php";<br />
$key = $_GET['u'];<br />
if($_GET["page"]){<br />
    $page=$_GET["page"];#获取要显示的页码<br />
}else{<br />
    $page=1;#没有参数传入时,显示第一页<br />
}<br />
$col=20;#每页显示记录条数<br />
$p=($page-1)*$col;<br />
$runSql = mysql_query("select * from cmsdj_song where uid = '$key' order by id desc limit ".$p.",".$col."");<br />
while($row = mysql_fetch_array($runSql))<br />
{<br />
//下面这些是调用值<br />
$sid=$row['id'];<br />
$suid=$row['uid'];<br />
$supip=$row['upip'];<br />
$name=$row['name'];<br />
$sname=substr($name,0,30);<br />
$sfile=$row['file'];<br />
$surl=$row['url'];<br />
$swjdx=$row['wjdx'];<br />
$stime=date('Y-m-d H:i:s',$row['addtime']);<br />
//$b64file=base64_encode($surl);<br />
?><br />
<table width='100%' border='0' cellpadding='0' cellspacing='0' class='tb_style'><br />
<tr><br />
<center><br />
<td width='5%' height='20' class='td_border'> <? echo $sid;?></td><br />
<td width='25%' class='td_border'><a href='u.php?i=<? echo $sfile;?>'> <? echo $sname;?></a></td><br />
<td width='20%' class='td_border'><a href='u.php?i=<? echo $sfile;?>'><? echo $sfile;?></a></td><br />
<td width='20%' class='td_border'><a href='u.php?i=<? echo $sfile;?>'><? echo $surl;?></a></td><br />
<td width='5%' class='td_border' align='center'><? echo $swjdx;?></td><br />
<td width='10%' class='td_border' align='center'><? echo $supip;?></td><br />
<td width='12%' class='td_border' align='center'><? echo $stime;?></td><br />
<td width='3%' class='td_border' align='center'><a href='del.php?id=<? echo $sid;?>'><img  src='/img/no.gif' border='0' alt=" PHP怎么按日期查询 " ></a></td><br />
</tr><br />
</center><br />
</table><br />
<?php<br />
}<br />
?>     <br />
<?php<br />
$col=20;#每页显示记录条数<br />
$count=mysql_query("select id from cmsdj_song where uid like '%$key%'");#取得记录总条数<br />
$num = mysql_num_rows($count)/$col;#计算页数<br />
$nnx = mysql_num_rows($count);#计算页数<br />
$num=ceil($num);#无条件小数进位确定总页数<br />
mysql_close();<br />
?>
Copy after login


------解决方案--------------------
FROM_UNIXTIME() UNIX时间戳转换为日期
UNIX_TIMESTAMP() 日期转换为UNIX时间戳
------解决方案--------------------
<br />
$u = $_GET['u'];<br />
<br />
$starttime = strtotime($u.'000000');<br />
$endtime =  strtotime($u.'235959');<br />
<br />
$runSql = mysql_query("select * from cmsdj_song where addtime > '$starttime' and addtime<'$endtime' order by id desc limit ".$p.",".$col."");<br />
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template