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

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

Ten Operator Syntax
Hi Guys,

I can't figure out why i am getting a parse error with this basic ten op code:

Execure stored procedure on a timer
Can someone tell me an easier way to execute a stored procedure on a timer? I am using Oracle 10g R

Calculating a rating by adding number of points and dividing by number of items
I have a site that users can post links to files to download. They can rate these files on a 1-5 sca

Adding to an Int row in db
Hi, i have a database which houses all of the users of my site. One of the columns is for points whi

Guixt issue
Hello all,

We are experiencing the following problem with Guixt:

Some transact

Query failed issue with php script but works fine in mssql manager!
hi i have the script below which copies data from one table to another but will only insert new data

Javascript or not?
How many people prefer javascript/ajax sites? How many prefer the good old fashion straight php sit

add 20 000 to the rowcnt
Hi ...
I need to add 20 000 to the row count but just cant find a way to do this i am new to php

The control with ID 'ace' requires a ScriptManager on the page
I'm trying to add a simple AlwaysVisibleControlExtender to my page, but it's not working. I get the

$_GET problem
Hi all,

Have a bit of a problem with a little piece of code, I am not sure if this should be

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