Php+mysql query specified date record of this month's data hits

Source: Internet
Author: User
Tags mysql query

$time = time ();
$days = 86400*30;
$sql = "SELECT * from Test where $time-updated< $days ORDER BY click_num desc limit 10";
$db = ' Daydb ';
$query = Mysql_db_query ($db, $sql, mysql_connect (' localhost ', ' root ', ' root '));
if ($query)
{
while ($rs = Mysql_fetch_array ($query))
{
echo $rs [' id '], $rs [' title '];
}
}
Else
{
Echo ' query failed ';
}

Example two query one year click the code
$days = 86400*365; Here to say 86400 represents a day.
$sql = "SELECT * from Test where $time-updated< $days ORDER BY click_num desc limit 10";
/*
Time () This function is to get the current server time truncation
Mysql_db_query SQL query execution direct with database tutorial
Mysql_connect Database Connection
Mysql_fetch_array saves the current record in an array
This site original tutorial reproduced annotated source http://www.111cn.net/phper/php.html
*/

Related Article

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.