Re: SQL / PHP Join issue.
| From: | clint | Date: | Tue, 22 Jan 2002 17:39:46 +0000 |
| Subject: | Re: SQL / PHP Join issue. | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-81574@lists.php.net to get a copy of this message | ||
You need to either alias the columns i.e. career.id as careerid or rename your columns i.e. change
the id to careerid & calendarid. The second option would be best because that way your columns
are descriptive.
HTH
Clint
---------- Original Message ----------------------------------
From: Michael O'Neal <mike@thinkmango.com>
Date: Tue, 22 Jan 2002 10:23:20 -0700
Hi,
I'm having a little trouble with this join statement I'm working on. What I
*think* is happening is that PHP is getting confused with the "ID" field
that is the same for the three different tables. When I go through the
result set, you can see that the field "ID" gets used a couple of times. I
have since tried to change the result set to call out the table as well (as
in "calendar.ID", but that didn't work. How can I give each "ID" field a
unique value to be used in the variables?
Here's my code:
$sql ="SELECT calendar.ID,calendar.Calendar_Title,calendar.Add_To_Scroller,
careers.id,careers.title,careers.Add_To_Scroller,
menu_specials.ID,menu_specials.Menu_Description,menu_specials.Add_To_Scrolle
r
FROM calendar,careers,menu_specials
WHERE calendar.Add_To_Scroller = 2
AND careers.Add_To_Scroller = 2
AND menu_specials.Add_To_Scroller = 2";
$result = @mysql_query($sql, $connection) or die("Error #". mysql_errno() .
": " . mysql_error());
while ($row = mysql_fetch_array($result)) {
$calendar_ID=$row['ID'];
$calendar_Calendar_Title=$row['Calendar_Title'];
$calendar_Add_To_Scroller=$row['Add_To_Scroller'];
$careers_id=$row['id'];
$careers_title=$row['title'];
$careers_Add_To_Scroller=$row['Add_To_Scroller'];
$menu_specials_ID=$row['ID'];
$menu_specials_Menu_Description=$row['Menu_Description'];
$menu_specials_Add_To_Scroller=$row['Add_To_Scroller'];
$display_block .= "Latest News -
$calendar_Calendar_Title|http://skunkworks.thinkmango.com/canyon/calendar/de
tail_action.php?ID=$calendar_ID|_self
Looking for a hot job? -
$careers_title|http://skunkworks.thinkmango.com/scroll/careers/career_detail
.php?id=$careers_id|_self
Great Deals on Great Food! -
$menu_specials_Menu_Description|http://skunkworks.thinkmango.com/scroll/menu
/menu_detail.php?ID=$menu_specials_ID|_self";
}
Thanks in advance!
mto
--
Michael O'Neal
Web Producer
---------------------
M A N G O
B O U L D E R
---------------------
http://www.thinkmango.com
e- mike@thinkmango.com
p- 303.442.1821
f- 303.938.8507
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net