php - Fetch multiple separated objects. -
$stmt = $db->prepare("select * friend join user on friend.uid=user.uid friend.friendid= ?"); $stmt->bind_param('s',$userid); if($stmt->execute()){ $user = $stmt->get_result(); while ($obj = $user->fetch_object()) { $friends[] = $obj; } echo json_encode($friends); }
my above code produced array
[{"uid":"2","firstname":"gem","lastname":"tang"},{"uid":"3","firstname":"james","lastname":"lebron"}]
but wish 2 object instead.
you have array of objects length 2. using javascript can traverse this.
var o = [{"uid":"2","firstname":"gem","lastname":"tang"},{"uid":"3","firstname":"james","lastname":"lebron"}]; for(var = 0; < o.length; i++) { var row = o[i]; console.log(row.firstname); }
Comments
Post a Comment