How does PHP query by date?

Source: Internet
Author: User
How does PHP query MYSQL field addtime as the timestamp by date? U = 20130328 & amp; page = 1 & nbsp; & amp; page = This is used to query data on the day of 20130328 or 20130329 by page & lt ;? Phpinclude & nbsp; "../PHP how to query by date
The addtime field in MYSQL is the timestamp.
I need to query it like this now
Xx. php? U = 20130328 & page = 1 & page = This is used for paging
In this way, you can query the data of 20130328 or 20130329 of the day.


 Include "../include/song. inc. php ";
$ Key = $ _ GET ['u'];
If ($ _ GET ["page"]) {
$ Page = $ _ GET ["page"]; # obtain the page number to be displayed
} Else {
$ Page = 1; # The first page is displayed when no parameter is input.
}
$ Col = 20; # number of records per page
$ 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 ))
{
// The following are the call values
$ 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; # number of records per page
$ Count = mysql_query ("select id from cmsdj_song where uid like '% $ key %'"); # retrieve the total number of records
$ Num = mysql_num_rows ($ count)/$ col; # Calculate the page number
$ Nnx = mysql_num_rows ($ count); # Calculate the page number
$ Num = ceil ($ num); # Use an unconditional decimal place to determine the total number of pages.
Mysql_close ();
?>

------ Solution --------------------
FROM_UNIXTIME () UNIX timestamp to date
UNIX_TIMESTAMP () date to UNIX timestamp
------ Solution --------------------

$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."");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.