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
7
Other forums
drop-down with sub-category appear
Hello,
i know how to build a simple dro-down list, im looking for a code when im gonna choose
foreach result into a single variable
Hi,
I have this code...
Code: [Select]foreach ($_POST['Interests'] as $interest =&
How a counter of users ? such as ---> (231 Viewing)
I want to count how many users are actually viewing the page, How is that possible?
Thank you guy
Saving data from a form into a file
Hey everybody,
Sorry, I am really new to PHP coding and such but a project kind of got thrust
PHP and MySQL Question/Help
I have a MySQL db with all my servers and all their details like server name, IP, OS, RAM etc etc 26
Extracting URL pointer within XML tag
Hi.
I'm trying to extract text between two quotation marks in XML. For example, I want to ex
Cache PHP Objects/Classes?
Does anyone have ideas about caching PHP objects using something like: http://memcached.org/
CURL XML Request [From C to PHP]
Hi,
I need some help converting this into something that will work with PHP.
Code: #
Need Successful Return
Hello I am currently working a form here, and I have everything figured out except when I click the
PHP doesn't send my mail
Hi all, I found this and used it to send mail. Simple contact form with some required fields. The va