十年網(wǎng)站開發(fā)經(jīng)驗 + 多家企業(yè)客戶 + 靠譜的建站團隊
量身定制 + 運營維護+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
/*今天*/
為鎮(zhèn)寧等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計制作服務(wù),及鎮(zhèn)寧網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為成都網(wǎng)站設(shè)計、成都網(wǎng)站制作、鎮(zhèn)寧網(wǎng)站設(shè)計,以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達到每一位用戶的要求,就會得到認可,從而選擇與我們長期合作。這樣,我們也可以走得更遠!
select?*?from?表名?where?to_days(時間字段)?=?to_days(now());
/*昨天*/
select?*?from?表名?where?to_days(now())-to_days(時間字段)?=?1;
/*近7天*/
select?*?from?表名?where?date_sub(curdate(),?interval?7?day)?=?date(時間字段);
/*查詢距離當(dāng)前現(xiàn)在6個月的數(shù)據(jù)*/
select?*?from?表名?where?時間字段?between?date_sub(now(),interval?6?month)?and?now();
/*查詢當(dāng)前這周的數(shù)據(jù)*/
select?*?from?表名?where?yearweek(date_format(時間字段,'%Y-%m-%d'))?=?yearweek(now());
/*查詢上周的數(shù)據(jù)*/
select?*?from?表名?where?yearweek(date_format(時間字段,'%Y-%m-%d'))?=?yearweek(now())-1;
/*查詢當(dāng)前月份的數(shù)據(jù)*/
select?*?from?表名?where?date_format(時間字段,'%Y-%m')=date_format(now(),'%Y-%m');
/*查詢上個月的數(shù)據(jù)*/
select?*?from?表名?where?date_format(時間字段,'%Y-%m')=date_format(date_sub(curdate(),?interval?1?month),'%Y-%m');
其它獲取類似以上的代碼顯示
SELECT COUNT(*) AS total FROM `logs` WHERE FROM_UNIXTIME(`create_time`,'%Y-%m')='2015-06'
//當(dāng)天時間
$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查詢到的數(shù)據(jù)存放到數(shù)組里面,一般使用$arr[]=$row的方式實現(xiàn),$row是mysql_fetch_array獲得的一行數(shù)據(jù),本身是一個數(shù)組,執(zhí)行上面的語句之后,這一行會添加存放在額為數(shù)組$arr的最后。
典型的例子代碼是這樣的:mysql_connect('127.0.0.1',
'root',
'123456');$sql='select
*
from
test.tab';if
($res=mysql_query($sql)){
while($row=mysql_fetch_array($res))
$result[]=$row;
mysql_free_resule($res);}else
echo
"執(zhí)行SQL語句:$sql\n錯誤:".mysql_error();echo
'查詢結(jié)果在下面的額為數(shù)組里面:';print_r($result);echo
'';