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
Expandable Post Code
Hi,
Hope you can help. Which currently I haven't upgraded to connect to a mysql server, so i
please help me... my password gets encrypted but not able to get in database
hai guys,
please help me... in the following function my password gets encrypted but no
PHP Search Issue
Hi, I am using the following code to search and return flights from a database. The user searches by
Code error with Index.php
Error: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/runevid/public_
Delete all from a table
I can not get the following code to work. If I run the sql statement in the db it will delete all t
Using CSS to format MySQL query
Hi,
If i want to have a news page on my site, which displays all records of a table in descen
problem when runing a funciton
I am trying to connect to database using a funciton in a functions.php
<?php
funct
Typing math
I've added support for typesetting math using LaTeX on the forums.
Example:
Code: [Select]
mysql select with $_get ?
Hi, i have this code:
Code: // If char id is 0 and character dont exist do:
if ($_GET["id
Must be a string? Huh, what? HELP?
with the following script, I get
Fatal error: Property name must be a string in /home/content/e/