therealwesfoster Posted February 1, 2008 Share Posted February 1, 2008 I have 3 tables. ----- events id_event title thumb date id_venue phone ----- venues id_venue name address phone ----- gallery id_gallery title id_event url thumb ----- I'm just wanting to grab all of their data where their id_event = 15. And I want to be able to put them into an array and call them by name. Here is what I've got. $sql = mysql_query ("SELECT e.*, v.*, g.* FROM events e JOIN venues v ON e.id_venue = v.id_venue LEFT JOIN gallery g ON g.id_event = e.id_event ORDER BY e.id_event DESC LIMIT 1") or die(mysql_error()); $row = mysql_fetch_array($sql); Then I want to echo it like so: echo $row['g.title']."<br />"; echo $row['e.title']; But nothing shows up unless I just echo $row['title']. But the problem with that is, I want to specify which table I'm echoing the data from (since gallery and events both have a title column) How? Quote Link to comment https://forums.phpfreaks.com/topic/88945-joining-3-tables-question/ Share on other sites More sharing options...
rhodesa Posted February 1, 2008 Share Posted February 1, 2008 You would have to call them as: SELECT e.title as event_title,g.title as gallery_title FROM events e JOIN venues v ON e.id_venue = v.id_venue LEFT JOIN gallery g ON g.id_event = e.id_event ORDER BY e.id_event DESC LIMIT 1 You should try to get in the habit of having unique column name like so: events event_id event_title event_thumb event_date venue_id event_phone ----- venues venue_id venue_name venue_address venue_phone ----- gallery gallery_id gallery_title event_id gallery_url gallery_thumb Quote Link to comment https://forums.phpfreaks.com/topic/88945-joining-3-tables-question/#findComment-455547 Share on other sites More sharing options...
therealwesfoster Posted February 1, 2008 Author Share Posted February 1, 2008 Thanks And I always use unique column names when doing my own stuff, but this is for someone else. Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/88945-joining-3-tables-question/#findComment-455550 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.