function getTowns($conn)
{
$sql = "SELECT towns.name, towns.id, regions.name AS region_name FROM towns INNER JOIN regions ON towns.region_id = regions.id ORDER BY name ASC";
$result = $conn->query($sql);
$town_opt = ''; //stands for town option
town_opt .= "<datalist id='townlist'>";
while ($row = $result->fetch_assoc()) {
$town_id = $row['id'];
$town_opt .= "<option>" . $row['name'] . ", " . $row['region_name'] . "</option>";
}
$town_opt .= "</datalist>";
return $town_opt;
};
echo $town_id;
echo getTowns($conn);
//how can I echo every town id?
This is the best I could think of, and yet it doesn't work. I tried setting a cookie but it still wasn't working the way I wanted.