2011-06-16 135 views
-1

我在這段代碼中得到一個未定義的索引錯誤:未定義指數

function get_userdata() { 
        global $db; 
        global $user; 
        global $data, $value, $line; 
        $id = $_SESSION['exp_user']['userid']; 
      $row = $db->query("SELECT * FROM tbl_staff WHERE id = $id"); 
     $user = array(); 
     while ($line = $row->fetch_assoc()) 
      {$user[ $line['data'] ] = intval($line['value']);} 
} 

誤差爲:

Notice: Undefined index: data in /includes/functions.php on line 11 

Notice: Undefined index: value in /includes/functions.php on line 11 

11號線是{$user[ $line['data'] ] = intval($line['value']);}

我在做什麼錯?

謝謝

+1

您確定在tbl_staff表中有一個名爲「data」的字段嗎? – 2011-06-16 15:36:20

+0

tbl_staff中很可能沒有數據和值列。 – 2011-06-16 15:37:14

回答

0

我假設你的變量$ line ['data']沒有返回一個原始值,即一個int或一個字符串。

這裏是我將如何構建數組。

while ($line = $row->fetch_assoc()){  
    $hc[] = $line['data']; 
    $hc[] = intval($line['value']); 
    $user[] = $hc; 
    unset($hc); 
} 

print_r($user); 
0

代碼被重複使用,但由於某種原因,數據表沒有被複制過。