Jump to content

[SOLVED] Help with query...


jmcall10

Recommended Posts

I have 3 tables:

 

tbl_people (pid, name);

tbl_events (eid, date);

tbl_people_events (peid, pid, eid);

 

so,

tbl_people stores peoples names;

tbl_events stores event dates;

tbl_people_events stores who attended what event;

 

 

I want to display a grid like effect with a 'Y' if someone has attended the event and a 'N' if they havnt

(pls see attachement)

Does this make sense?

 

 

[attachment deleted by admin]

Link to comment
Share on other sites

with this, since it is very much dependent on dates, what i usually do is that i create a derived table which will compose of the dates i want, then from there, base tbl_people_events (use left join to check those present and not present) and joins with the other tables.

 

to arrange the display, use group by then order by. :)

 

 

Link to comment
Share on other sites

$results = SELECT * FROM (tbl_people LEFT JOIN tbl_people ON tbl_people_events.pid = tbl_people.pid)
LEFT JOIN tbl_events ON tbl_people_events.eid = tbl_events.eid;
while ($data = mysql_fetch_array($results)) { 
//Display your table using $data['name'] etc...

 

You would also need another field for the dates.  I haven't tested this code it probably doesn't work but it should give you an idea.

Link to comment
Share on other sites

well to be perfectly honest I am really rotten at sql so when it comes to joining tables I am completely lost.

 

So I guess I have nothing. I tried using the above qwuery and couldnt get it to execute. I dont have enough knowledge or experience to edit it.

 

Could you please help me on this one?

Link to comment
Share on other sites

yea I have dynamically created a table like:

 

<table border="1" align="center">

<tr>
<td></td>
<?PHP
$events = mysql_db_query($database, "SELECT * FROM tbl_events ORDER BY date asc") or die ("$DatabaseError");
while (
$qry1 = mysql_fetch_array($events)) 
{
echo "<td>$qry1[date]</td>"; 
}
?>
</tr>

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.