思路:先關(guān)聯(lián)數(shù)據(jù)庫,然后執(zhí)行sql語句,最后返回結(jié)果!
網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)公司!專注于網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、微信小程序開發(fā)、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了牙克石免費建站歡迎大家使用!
需要關(guān)聯(lián)上數(shù)據(jù)庫
?php
//創(chuàng)建對象并打開連接,最后一個參數(shù)是選擇的數(shù)據(jù)庫名稱
$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(時間字段名)";
//執(zhí)行sql語句,完全面向?qū)ο蟮?/p>
$result?=?$mysqli-query($sql);
while($row?=?$result-fetch_array()){
echo?$row[0];
}
?
執(zhí)行一條sql語句
SELECT?*FROM?表名?where?DATE_SUB(CURDATE(),?INTERVAL?7?DAY)?=?date(時間字段名)
3.運行結(jié)果、返回結(jié)果集:
$result=mysql_query($query);
并對結(jié)果進(jìn)行處理!
echo date('Y-m-d',strtotime ( "last Monday -1 week" )), "\n" ;
echo date('Y-m-d',strtotime ( "last Sunday" )), "\n" ;
通過這個函數(shù)獲取上個周的開始和結(jié)束,然后sql查詢
可以研究下這個函數(shù)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));??//天數(shù)
//echo?'br/';
$starttime?=?$nowtime?-?($tianshu*24*3600);
$wheresql?.=?"?AND?paidan_time='$starttime'?";*/
}
}