How can I have the php script return json without the square brackets? I am also getting the INT values back with double quotes for some reason. Is it possible to remove those as well?
What I am getting now:
[{"id":"1","name":"Jack","username":"Jack1","age":"23"}]
What I would like:
{"id": 1,"name":"Jack","username":"Jack1","age":23}
The following is the php script that returns the JSON:
<?php
$con = mysqli_connect("localhost", "username", "password", "database");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// This SQL statement selects ALL from the table 'Equipment'
$username = $_POST['username'];
$password = $_POST['password'];
$sql = "SELECT username, name FROM DriverInfo WHERE (username = '$username') and password = '$password' ";
// Check if there are results
if ($result = mysqli_query($con, $sql)) {
// Create temporary connection
$resultArray = array();
$tempArray = array();
// Look through each row
while ($row = $result->fetch_object()) {
// Add each row into our results array
$tempArray = $row;
array_push($resultArray, $tempArray);
}
// Finally, encode the array to JSON and output the results
echo json_encode($resultArray);
}
mysqli_close($con);