Jump to content

Getting an order from query


SneakyMax

Recommended Posts

Okay, this is my first post so don't go too hard on me...

I've been using php for about 2 months now, got the basics. My problem is that for the thing that I am making online, it uses two different mysql tables to 'simplify' things, so I don't have too many columns.

The first table, for my nation simulation, has these things:
nation id, first name, last name
And the second table has these:
nation id
population

I have a script that lists all of the nations, and in order of different things. Such as nation id and nation name, using "SELECT * from [table1] ORDER BY 'nationid' ASC
To order by nation id

The problem is I don't know how to order it by population, since it's in a different table. The nation ids in table 2 go with the nation ids from table 1, but I don't know how to get the order of population from table 2, then use that order in table 1 to get the name.

Hope it's not too confusing...it might have to do with sql, or mysql_fetch_array probably.
Link to comment
https://forums.phpfreaks.com/topic/8588-getting-an-order-from-query/
Share on other sites

you can either pull all the information from the second table out along with the first one.

[code]"select * from table1 t1, table2 t2 order by t2.population asc"[/code]

or its more likely you'll want to join the two tables on their common key

[code]"select * from table1 t1 INNER JOIN table2 t2 on t1.nationid = t2.nationid order by t2.population asc"[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.