I have a table (see image below) that includes the polish and latin names for a selection of different herbs.
I'd like to obtain a $herbs[]
array, that contains an array for each row, e.g.:
$herbs = [[mieta pieprzowa, mentha piperita],[kozlek lekarski, valeriana medicinalis]...]
The code for receiving latin_name
looks like this, so what should I change?
<?php
$connection = new mysqli("127.0.0.1","root","password","herbarium");
if ($connection→connect_error) die("Fatal Error");
$herb = $_GET['q'];
$query = "SELECT * FROM herbs WHERE (latin_name LIKE '%$herb%') OR (polish_name LIKE '%$herb%')";
$result = $connection→query($query);
$data = array();
while ($row=$result→fetch_assoc()){
$data[] = $row['latin_name'];
}
echo json_encode($data);
?>