0
I am building an API in PHP/Mysql that will feed a hybrid APP, also under construction, via Ionic. Data transit is via Json.
I guess I’m new to Ionic, Angular, JS, and Json... Reasonable in PHP and Mysql. I mean... heeeeelllllp 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";
I close the connection
mysqli_close($connection);
It works!!! Each item is encoded correctly and Ionic interprets ok (relatively ok... html formatting, line breaking etc are not interpreted in the app, but it’s a question for another question.).
What I need then?
I want to include data beyond 'select', encoding and sending to Ionic.
Ex.: Place the variable
$site=www.com.br;
$autor=Pedro;
And they, even if they don’t come from Mysql, are added to Json.
Thank you for answering. It turns out that it didn’t work fully, I’m sorry, due to a detail not mentioned in the question, the following: A $emparray[] item is dynamic (but custom) coming from the comic book. I put inside while{} and even pulls it right but only once, it is not in a looping (in the case 10 items / limit 10).
– Leonel Junior