I'm getting an undefined index error in this code:
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']);}
}
Error being:
Notice: Undefined index: data in /includes/functions.php on line 11
Notice: Undefined index: value in /includes/functions.php on line 11
Line 11 being {$user[ $line['data'] ] = intval($line['value']);}
.
What am I doing wrong?
Thanks
I am assuming your variable $line['data'] does not return a primitive value, i.e. an int or a string.
Here is how i would build the array.
while ($line = $row->fetch_assoc()){
$hc[] = $line['data'];
$hc[] = intval($line['value']);
$user[] = $hc;
unset($hc);
}
print_r($user);
Code was reused, but for some reason, the data table hadn't been copied across.
精彩评论