I am having some problem on exporting the result of a Prepared Statement using MySQLi.
$age = "young";
$rows = array();
$mysqli = new mysqli($db_hostname, $db_username, $db_password, $db_database);
$stmt = $mysqli->prepare("SELECT fname, lname FROM users WHERE age=?");
$stmt->bind_param('s', $age);
$stmt->execute();
$stmt->bind_result($thefName,$thelName);
while($stmt->fetch())
{
array_push($rows, $thefName,$thelName);
}
$stmt->close();
$mysqli->close();
echo json_encode($rows);
as you can see I am trying to echo out the json_encode($rows);
each of rows as a JSON Array like this :
[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter","lastName":"Jones"}
]
but what I am getting is
["John", "Doe", "Anna", "Smith", "Peter", "Jones"]
Can you please let me know why this is happening and how I can fix it