2013-03-07 50 views
0

我在這裏查詢這個查詢,爲了得到某個列的總和,但是我總是收到錯誤Undefined index從查詢中檢索SUM結果的問題

$sql_shuma="SELECT SUM(vlera) AS shuma " 
      ."FROM servis_pjeset_perdorura " 
      ."WHERE random = $random"; 
$resultshuma = odbc_exec($connection, $sql_shuma) or die(odbc_error()); 

while($rowshuma = odbc_fetch_array($resultshuma)) { 
    echo $total1 = $rowshuma['shuma']; 
} 
?> 

我在這裏做錯了什麼?也許這是$total1的值,我不知道如何保存結果。

謝謝

+0

它似乎是PHP而不是SQL問題。我建議你在你的文章中加入[PHP]標籤。 – 2013-03-07 14:06:28

+1

做一個'print_r($ rowshuma)'看看裏面有什麼。根據用戶對[odbc_fetch_array()文檔](http://us3.php.net/manual/en/function.odbc-fetch-array.php)的評論,它可能並不總是返回一個關聯數組。鍵可以是數字。 – 2013-03-07 14:17:23

回答

0

是$ random是一個整數嗎?如果不是,你必須使用''來分隔字符串,像這樣:

$sql_shuma="SELECT SUM(vlera) AS shuma FROM servis_pjeset_perdorura WHERE random = '$random'";