Grouping and sorting results


Posted on 16th Feb 2014 07:03 pm by admin

Please help with this query.

I have 2 tables in a database, countires and cities. states looks like this

Did you know?Explore Trending and Topic pages for more stories like this.
countries

id -----------country
1 ------------uk
2 ------------us
3 ------------japan

cities
id ---country ----city
1 ----1 ----------London
2 ----1 ----------Manchester
3 ----2 ----------New York
4 ----2 ----------Washington
5 ----2 ----------San Francisco
6 ----2 ----------Las Vegas
7 ----2 ----------New Orleans
8 ----3 ----------Tokyo


I have queried the database as follows:

///////////////////////// Make the country query //////////////////////////////
$q_country = "SELECT * FROM countries";
$result_country = mysqli_query($dbc, $q_country);
$row_country = mysqli_fetch_array($result_country);

///////////////////////// Make the city query //////////////////////////////
$q_city = "SELECT * FROM cities";
$result_city = mysqli_query($dbc, $q_city);
$row_name = mysqli_fetch_array($result_name);

I want to display the data as follows:

Country - UK
Cities - London, Manchester

Country - US
Cities - New York, Washinton, San Francisco, Las Vegas, New Orleans

Country - Japan
Cities - Tokyo

I'm new to PHP and just can't work it out. Please can somebody point me in the right direction?!!!! PLEASE!!!!!
No comments posted yet

Your Answer:

Login to answer
98 Like 7 Dislike
Previous forums Next forums
Other forums

start new row of pictures
on my site www.budstreasureauctions.com there is a featured auctions box that users will pay to get

Menu restriction
How can I restrict the individual menu that would appear when a user logs in so that all users are c

PHP / MySQL Associative Multidimensional Array:
Hello.

I have data in a MySQL Table that adheres to the below: (note, no index, could add if

On page view, minus credit
Hello all, please, I need a little help with this script. I am charging one credit (credits can be p

Different payment methods with different cross company requirements in F110
We are implementing SAP in a company in the shipping industry. They have the following requirement:<

Mail Script Problems
I have created a PHP mail script. I am having a problem though. In $body i am trying to put two va

php/xmlrpc class issue
I am working on xml-rpc in php to start with.

I have a class that only has variables defined

Best PHP Documentation generator
Hello guys!

I would like to hear from you what is the best PHP documentation generator. Perso

returning data from an ssh2_exec()
here's what i got.


$conn = ssh2_connect($this->_host);
ssh2_auth_password($c

Check something, wait, check again, do something!
Hi guys.

I wonder if someone can help me with this.

Basically, what I want to do is (

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash