I'm iOS developer and for finishing prototype I need simple php code which could return data from particular table as JSON. Here is a code I developed:
<?php
$connection = mysqli_connect($db_host, $db_user, $db_pass, $db_database) or die(mysql_error());
$query = "select * from Events" or die("Error in the consult.." . mysqli_error($connection));
$result = $connection->query($query);
$events = array();
while ($event = $result->fetch_array(MYSQLI_ASSOC)) {
$events[] = $event;
}
echo json_encode($events);
$result->free();
$connection->close();
?>
The problem is that it duplicates data fields. Here is a result I receive:
[
{
"0":"1",
"id":"1",
"1":"Some title",
"title":"Some title"
}
]
In database I have one record only.
How to solve the following problem?