In my application I'm trying to print out information with a foreach. The SQL is written correctly. When I do a var_dump of my function I get the correct information with:
$eventgroupinfo = $event->GetEventGroupInfoByEventGroupId($event_group_id);
var_dump($eventgroupinfo);
When I try to print it out it is giving this error:
Warning: Illegal string offset
But I get the information when I var_dump it. What am I doing wrong?
FOREACH
foreach ($eventgroupinfo as $g) {
echo $g['user_id'] . $g['avatar'];
}
FUNCTION:
public function GetEventGroupInfoByEventGroupId($event_group_id)
{
$db = new Db();
$select = "SELECT
p.event_progress_id,
p.user_id,
p.event_progress_distance,
p.event_progress_date,
p.event_group_id,
u.user_id,
u.name,
u.surname,
u.avatar
FROM tblevent_progress p INNER JOIN tblusers u ON p.user_id = u.user_id
WHERE p.event_group_id = " . $event_group_id ;
var_dump($select);
$result = $db->conn->query($select);
return $data=$result->fetch_assoc();
}
}
VAR_DUMP RESULTS
array (size=8)
'event_progress_id' => string '1' (length=1)
'user_id' => string '1' (length=1)
'event_progress_distance' => string '2532' (length=4)
'event_progress_date' => string '2014-05-10 12:48:27' (length=19)
'event_group_id' => string '50' (length=2)
'name' => string 'Vandenbergh' (length=11)
'surname' => string 'Jan' (length=3)
'avatar' => string '139404100.jpg' (length=21)
var_dumpresults, otherwise we don't know the structure of your array.