Jump to content

joins between three mysql tables


lional

Recommended Posts

Hi,

I have a site where a client requests to join a particular event.

From a management site I would like to list the clients who have requested the events specifying if they have attaended the event before so that new applicants will get preference.

My tables are as follows.

Clients table - I would like to pull the following filelds: fullnames, idno, tel (each client is assigned an unique client_id

Event request - I would like to pull the event ID (The fileds in this table are client_is, event_id)

Event_booking_history - I would like to pull the amount of times the client has donae a particular event. (the fileds in this table are clieny_id, event_id, no_of_times)

 

I am trying to pull a list from this tables that would list fullname, tel, idno, no_of_times for a specific event that us selected from a drop-down box. I would like check boxes so that I can select which clients can attend which events.

 

here is my code so far

<?php
$query_town = "SELECT clients.fullnames, clients.idno, clients.tel, event_request.event_id, event_booking_history.no_of_times FROM clients, event_request, event_booking_history WHERE event_request = '$bucket_list_out'";
$result_town = mysql_query($query_town) OR die(mysql_error());
while ($row_town = mysql_fetch_assoc($result_town)) {
$town_out = $row_town["clients.fullnames"];
$town_out = $row_town["clients.idno"];
$town_out = $row_town["clients.tel"];
$town_out = $row_town["event_booking_history.no_of_times"];
?>

Thanks

Lional

 

Link to comment
Share on other sites

try

SELECT clients.fullnames, clients.idno, clients.tel, 
    event_request.event_id, 
    event_booking_history.no_of_times 
FROM clients 
    INNER JOIN event_request 
        ON clients.idno = event_request.client_id 
    INNER JOIN event_booking_history 
        ON event_booking_history.event_id = event_request.event_id
WHERE event_request.event_id = '$bucket_list_out'

You cannot have WHERE tablename = 'x', it has to be a columnname or expression (I assumed event_id)

 

Table names are not output with the column names so use

 

$row['idno']

 

and not

 

$row['clients.idno']
 

Link to comment
Share on other sites

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.