Got a few tables, how do i join the information on 1 page?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
boom4x
Forum Newbie
Posts: 16
Joined: Mon Mar 08, 2004 2:10 pm
Location: New York, NY
Contact:

Got a few tables, how do i join the information on 1 page?

Post by boom4x »

Hello,

I have a page which is suppose to show information from the database with multiple tables.

How do i use join for these 2 tables to show the info on one page?

Here is my original code:

Code: Select all

$result = mysql_query("SELECT * FROM list",$db);
while ($info = mysql_fetch_array($result))
and im using

Code: Select all

echo $info['name'];
to display any field.

Just in case you're wondering this is not the full code...
it works just fine.

Now if i wanted to get the info from 2 tables i tried:

Code: Select all

$result = mysql_query("SELECT * FROM list,cities WHERE cities.id list.id=$id",$db);
	$info = mysql_fetch_array($result);
Doesn't work... and also how do i display it once i get it going?
Maybe something like this

Code: Select all

echo $info['cities.id'];
Let me know what u think.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Try SELECT * FROM list,cities WHERE cities.id=list.id and cities.id=$id
That should work, you need to set the actual join of cities.id=list.id as well as define what the id should be.

Regards
Post Reply