大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
思路:先关联数据库,然后执行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);
并对结果进行处理!
echo date('Y-m-d',strtotime ( "last Monday -1 week" )), "\n" ;
echo date('Y-m-d',strtotime ( "last Sunday" )), "\n" ;
通过这个函数获取上个周的开始和结束,然后sql查询
可以研究下这个函数strtotime 。可以满足你的需求
/时间短查询
$starttime=GetMkTime($starttime);
$endtime=GetMkTime($endtime);
if($issettime==1){
if(!empty($starttime) !empty($endtime)){
$wheresql .=" AND paidan_time BETWEEN $starttime AND ".$endtime."";
}else if(!empty($starttime) empty($endtime)){
$endtime=time();
$wheresql .=" AND paidan_time BETWEEN $starttime AND ".$endtime."";
}else if(empty($starttime) !empty($endtime)){
$starttime=GetMkTime("2012-1-1");
$wheresql .=" AND paidan_time BETWEEN $starttime AND ".$endtime."";
}
}else if($issettime==2){
if(!empty($starttime) !empty($endtime)){
$wheresql .=" AND shousu_time BETWEEN $starttime AND ".$endtime."";
}else if(!empty($starttime) empty($endtime)){
$endtime=time();
$wheresql .=" AND shousu_time BETWEEN $starttime AND ".$endtime."";
}else if(empty($starttime) !empty($endtime)){
$starttime=GetMkTime("2012-1-1");
$$wheresql .=" AND shousu_time BETWEEN $starttime AND ".$endtime."";
}
}else
{
if(!empty($starttime)){
if($isset=="jr"){
$starttime=GetDateMK($starttime);
$wheresql .=" AND datediff('".$starttime."',FROM_UNIXTIME(`paidan_time`))=0 ";
}else{
//$endtime=time();
$wheresql .=" AND paidan_time BETWEEN $starttime AND ".$endtime."";
}
/*$nowtime = time();
$passtime=$nowtime-$starttime;
$tianshu=floor($passtime/(24*60*60));
echo floor($passtime/(24*60*60)); //天数
//echo 'br/';
$starttime = $nowtime - ($tianshu*24*3600);
$wheresql .= " AND paidan_time='$starttime' ";*/
}
}