Answer the question
In order to leave comments, you need to log in
How to retrieve multiple values from a row from a database?
Good afternoon. There is a database with
country_name and city_name columns.
How to correctly form a query to display not only the name of the city, but also the country?
if(!empty($_POST["keyword"])) {
$query ="SELECT * FROM country WHERE city_name like '" . $_POST["keyword"] . "%' ORDER BY city_name LIMIT 0,5";
$result = $db_handle->runQuery($query);
if(!empty($result)) { ?>
<ul id="country-list">
<?php
foreach($result as $country) {
?>
<li onClick="selectCountry('<?php echo $country["city_name"]; ?>');"><?php echo $country["city_name"]; ?></li>
<?php } ?>
</ul>
<?php }
}
Answer the question
In order to leave comments, you need to log in
SELECT city_name, city_country FROM country WHERE city_name like ........
.........');"><?php echo $country["city_country"]; ?><?php echo $ country["city_name"]; ?>
Why * if you only need two columns?
select CONCAT(country_name, ' ', city_name) as Country_City
from country
where city_name like '%%';
select country_name + ' ' + city_name AS Country_City
from country
where city_name like '%%';
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question