I have a mobile app, I have a array
to be generated through php what I intend now and in angularjs
transform the array into an object because when I want to get for example the id gives undefenid because it is like array
and has to be object would like to know how can I transform that array
than well of php into an object?
PHP
$result_posts_home = $conexao->prepare("SELECT * FROM posts_home WHERE activo = :activo ORDER BY id DESC ");
$result_posts_home->bindValue(':activo', 1, PDO::PARAM_INT);
$result_posts_home->execute();
$posts_home = $result_posts_home->fetchAll(PDO::FETCH_OBJ);
foreach ($posts_home as $row_posts_home) {
$result_posts_home_anexos = $conexao->prepare("SELECT * FROM posts_home_anexos WHERE id_mae = :id_mae AND seccao = :seccao ");
$result_posts_home_anexos->bindParam(':id_mae', $row_posts_home->id, PDO::PARAM_INT);
$result_posts_home_anexos->bindValue(':seccao', 'thumbnail', PDO::PARAM_STR);
$result_posts_home_anexos->execute();
$row_posts_home_anexos = $result_posts_home_anexos->fetch(PDO::FETCH_OBJ);
// VALIDA SE USER JA TEM LIKE NO POST
$total_likes = $conexao->prepare("SELECT * FROM likes WHERE id_post = :id_post AND user_id = :user_id ");
$total_likes->bindValue(':id_post', $row_posts_home->id, PDO::PARAM_INT);
$total_likes->bindValue(':user_id', $_SESSION['user_id'], PDO::PARAM_INT);
$total_likes->execute();
$likes = $total_likes->fetch(PDO::FETCH_ASSOC);
$noticias[] = array(
'id' => $row_posts_home->id,
'id_anexo' => $row_posts_home_anexos->id_anexo,
'tipo' => $row_posts_home_anexos->tipo,
'likes' => $row_posts_home->likes,
);
}
echo json_encode($noticias);
Controller
.controller('ListaNoticiasHome', function($scope, $http, $stateParams, sessionService, $partilharRecursos) {
$http.get("https://www.sabeonde.pt/api/api_noticias_home.php").success(function (data) {
$scope.noticias_home = data;
$partilharRecursos.set('idNoticia', data.id);
});
})