php查询本周的数据 php查询语句

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

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

需要关联上数据库

?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);

并对结果进行处理!

thinkphp 怎么查本周 本月时间范围内的数据

求本周的开始和结束时间

$w = date(‘w’,time()) – 1;

$start_time = time() – $w * 60 * 60 * 24;         //星期一的时间戳

$end_time = time() + (6 – $w) * 60 * 60 * 24; //星期天的时间戳

M(‘tablename’)-where(“create_time =  或型戚{ $start_time} and create_time 租枯= $end_time”)-select();

月份的也很简单了,求出本月开始和结束的衫陵时间,然后在根据时间查询就可以了

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’))

);