我遇到了這個PHP函數的問題。它保持返回零,但我知道SQL語句的工作原理,因爲我自己查詢過它。任何想法我做錯了什麼?最後一行對我來說沒有意義......我在編輯別人寫的代碼。這個函數應該返回一個數字,假設日期是三月。謝謝!PHP函數返回ZERO
function getCountBetweenDays($day1,$day2,$service)
{
global $conn;
if ($service==1){
$query = "SELECT COUNT(*) as NUM FROM `items` WHERE `modified` BETWEEN '$day1 00:00:00' AND '$day2 23:59:59';";}
elseif($service==2){
$query = "SELECT COUNT(*) as NUM FROM `items` WHERE `modified` BETWEEN '$day1 00:00:00' AND '$day2 23:59:59';";}
elseif($service==3){
$query = "SELECT COUNT(*) as NUM FROM `items` WHERE `modified` BETWEEN '$day1 00:00:00' AND '$day2 23:59:59';";}
$result = mysql_query($query,$conn);
$num = mysql_fetch_array ($result);
return $num['NUM'];
}
指數我缺少的東西還是真的在查詢沒有區別? – 2010-03-30 22:11:31
在這三種情況下,$ query都包含相同的字符串......是故意的嗎? – VolkerK 2010-03-30 22:11:42
$ day1,$ day2和$ service的值是什麼?你能迴應他們嗎? – 2010-03-30 22:13:25