View Full Version : one more for the nite then bed time, question on Joins

08-27-2006, 01:26 PM
I think this is working ok (it looks like, the right stuff is showing up, in the right order).
Not real sure on inner/outer/left and what ever else type of joins, still have some reading to do.

$result = mysql_query("SELECT a.ID, a.menu_id, a.submenu_title, a.display_order, b.menu_title, b.display_order FROM page_content as a JOIN menu as b ON (a.menu_id=b.ID) ORDER BY b.display_order,a.display_order",$db);
Any way here's my question, I have two fields in the tables that are named the same "display_order" and I cant figure out how to access both from this querry?

$var_menu_title = $MyRow['menu_title'];
$var_submenu_title = $MyRow['submenu_title'];
$var_menu_order = $MyRow['display_order'];
I am able to get menu_title from table b, submenu_title from table a, but display_order gives me display_order for table b(menu), I would have thought that would give me display_order for table a(page_content). how would I access both display_order fields from the different tables, I would like to list both.

08-27-2006, 01:51 PM
What you do is give the columns alias names in your select. As in, "SELECT a.display_order as content_order, b.display_order as menu_order". Then in your associative array the index names come out as "content_order" and "menu_order".

This is also handy for selecting formatted data, like "SELECT date_format(start_date, '%y %m %d') as startdate". Without the alias, the index name becomes "date_format(start_date, '%y %m %d')"... nasty stuff!

08-27-2006, 10:05 PM
Fumigator, Thanks much you've been a hugh help the last couple of days.

08-27-2006, 11:28 PM
You're welcome :)