php查询本周数据,PHP查询-成都创新互联网站建设

关于创新互联

多方位宣传企业产品与服务 突出企业形象

公司简介 公司的服务 荣誉资质 新闻动态 联系我们

php查询本周数据,PHP查询

php+mysql怎么查询本周的数据

思路:先关联数据库,然后执行sql语句,最后返回结果!

成都创新互联是专业的麻山网站建设公司,麻山接单;提供网站制作、成都做网站,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行麻山网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!

需要关联上数据库

?php

//创建对象并打开连接,最后一个参数是选择的数据库名称

$mysqli = new mysqli('localhost','root','','volunteer');

//检查连接是否成功

if (mysqli_connect_errno()){

//注意mysqli_connect_error()新特性

die('Unable to connect!'). mysqli_connect_error();

}

$sql = "SELECT *FROM 表名 where DATE_SUB(CURDATE(), INTERVAL 7 DAY) = date(时间字段名)";

//执行sql语句,完全面向对象的

$result = $mysqli-query($sql);

while($row = $result-fetch_array()){

echo $row[0];

}

?

执行一条sql语句

SELECT *FROM 表名 where DATE_SUB(CURDATE(), INTERVAL 7 DAY) = date(时间字段名)

3.运行结果、返回结果集:

$result=mysql_query($query);

并对结果进行处理!

PHP如何获取本周和本月的数据进行排行

计算本周的,需要对今天进行判断,先计算出是星期几,然后计算出星期一是 几月几号,在算出星期天是几月几号, 然后在写到sql中,比如 2009-03-09到2009-03-15的话,sql就是

SELECT count( ID ) AS c FROM dede_archives WHERE UNIX_TIMESTAMP( '2009-03-15') pubdate UNIX_TIMESTAMP('2009-03-09') 下面还有一例。本月统计(MySQL)

select * from booking where month(booking_time) = month(curdate()) and year(booking_time) = year(curdate())本周统计(MySQL)

select * from spf_booking where month(booking_time) = month(curdate()) and week(booking_time) = week(curdate())

thinkphp中如何查询当天,本周的,本月的,本年的数据,

//当天时间

$where['time'] = array(

array('egt',strtotime(date('Y-m-d',time())),

array('lt',strtotime(date('Y-m-d',time())).'+1 day')

);

// 本周时间

$where['time'] = array(

array('egt',strtotime(date('Y-m-d',time())).'-'.date('w',time()).' day'),

array('lt',strtotime(date('Y-m-d',time())).'+1 week -'.date('w',time()).' day');

);

// 本月时间

$where['time'] = array(

array('egt',strtotime(date('Y-m',time()))),

array('lt',strtotime(date('Y-m',time()).'+1 month'))

);

// 本年时间

$where['time'] = array(

array('egt',strtotime(date('Y',time()))),

array('lt',strtotime(date('Y',time()).'+1 year'))

);

上面是查询条件,直接运用到查询语句就可以了

$result = $db-where($where)-select();

更正下上面的那个 本年 查询时间

$where['time'] = array(

array('egt',strtotime(date('Y-01-01',time())),

array('lt',strtotime(date('Y-01-01',time()).'+1 year'))

);


分享题目:php查询本周数据,PHP查询
文章起源:http://kswsj.cn/article/hocgod.html

其他资讯