Page 1 of 1

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

Posted: Tue Mar 23, 2004 12:34 am
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.

Posted: Tue Mar 23, 2004 2:41 am
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