I have a page which creates an instance of a class. This class gets some information on the user (their badges) but when I return the object I only get the first record. Some code below.
$badges = new Badges;
$result = $badges->getBadges($userID);
$row_array[] = $result;
echo json_encode($row_array);
class Badges
{
function getBadges($userID)
{
$get_badge_query = mysqli_query($GLOBALS['connect'], "SELECT * FROM tbl_my_badges WHERE user_id = '" . $userID . "'");
while($get_badge_result = mysqli_fetch_assoc($get_badge_query)) {
$result = array("done" => "true",
"badge_icon" => $get_badge_result['badge_icon'],
"badge_text" => $get_badge_result['badge_message']);
}
return $result;
}
}
I have tried adding an array variable outside the loop and populating this with the results and returning the variable but still doesn't work.
Any help would be great.
$result = array("done" => "true",...line of code does.SELECTing one record, unless you have multiple people with the same$userId.