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
https://forums.phpfreaks.com/topic/124306-solved-help-with-query/
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. :)

 

 

$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.

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?

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>

Ok I think I have sorted this out.

 

I have posted a new topic in the php forum to see if it is the most efficient way.

 

For those that were tracking this thread you can find the above mentioned post at:

 

http://www.phpfreaks.com/forums/index.php/topic,216877.0.html

 

Thanks for all your help guys

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.