I'm trying to figure out how to save SQL query results into array:
This loop only produces 1 result in array:
<?php
$term = $_GET['term'];
$query = "SELECT * FROM Bob WHERE h_city LIKE '%".$term."%' ORDER BY
h_city ASC";
$result = mysqli_query($conn, $query);
while($row = mysqli_fetch_assoc($result)) {
$result = $row['h_city'];
array_push($result);
}
$json = json_encode(array($result));
echo $json;
?>
result is: ["example1"] How to save query into array like ["example1","example2"]. Any thoughts what I might be doing wrong, or anyone can point me to the right direction?
EDIT as it was mentioned in the comments this way of doing queries is prone to SQL injections: more info here more info on converting results to arrays: more info here