I'm building an API in PHP / Mysql that will feed a hybrid APP, also under construction, via Ionic. The data traffic is via Json.
I'm a newcomer to Ionic, Angular, JS, and Json ... Reasonable in PHP and Mysql. I mean ... heeeeelllllllp please !!!
In practice I make a select:
$sql = "select id, titulo, ano from tabela WHERE titulo!='' ORDER by id DESC LIMIT 10";
$result = mysqli_query($connection, $sql) or die("Error in Selecting " . mysqli_error($connection));
I create an array
$emparray = array();
while($row =mysqli_fetch_assoc($result))
{
$emparray[] = $row;
}
Encodo
echo json_encode($emparray), "\n";
Close the connection
mysqli_close($connection);
It works !!! Each item is encoded correctly and Ionic interprets ok (relatively ok ... html formatting, line break etc are not interpreted in the app, but it's a question for another question.)
What do I need then?
I want to include data beyond what's 'select', encode and send it to Ionic.
Eg: Placing the variable
$site=www.com.br;
$autor=Pedro;
And they, even if they do not come from Mysql, are added in Json.