Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/88945-joining-3-tables-question/
Share on other sites

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.