sportsreport2 Posted August 24, 2011 Share Posted August 24, 2011 First off i have three tables in a database. One is called "student" which has fields student_id, firstname and lastname. The next table is called "class" which has class_id, title, date. The last table is called "att" which has a att_id, class_id, student_id. I am trying to display every students first and last names and show whether or not they have attended a class but only show attendance for one class per page. Example: Page 1 (Title1, date1) Firstname Lastname, attended Firstname Lastname, did not attend Firstname Lastname, did not attend Firstname Lastname, attended Firstname Lastname, attended But i can't seem to figure out how to have every students name displayed when they haven't attended the class. I tried to use a Left Join to join student and att tables then display firstname and lastname but when i put WHERE title_id it changes and only shows the students who have attended the class. Help Please Quote Link to comment https://forums.phpfreaks.com/topic/245544-mysql-left-join-help/ Share on other sites More sharing options...
fenway Posted August 24, 2011 Share Posted August 24, 2011 Show us the query you have now. Quote Link to comment https://forums.phpfreaks.com/topic/245544-mysql-left-join-help/#findComment-1261394 Share on other sites More sharing options...
sportsreport2 Posted August 24, 2011 Author Share Posted August 24, 2011 <table width="20%" border="1" cellspacing="0" cellpadding="0" align="center"> <tr> <td><strong>Name</strong></td> <td><strong>Attendance</strong></td> </tr> <? $result = mysql_query(" SELECT * FROM student LEFT JOIN att ON student.student_id=att.student_id WHERE class_id=1 "); while($row = mysql_fetch_array($result)) { ?> <tr> <td align="center"><? echo $row['firstname']; ?> <? echo $row['lastname']; ?></td> <td align="center">(NOT SURE WHAT TO PUT HERE i would like it to say attended or not attended based on if they did or not)</td> </tr> <? } ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/245544-mysql-left-join-help/#findComment-1261456 Share on other sites More sharing options...
Maq Posted August 24, 2011 Share Posted August 24, 2011 - Don't use short tags () use <?php. - Your actual JOIN looks fine. I tried to use a Left Join to join student and att tables then display firstname and lastname but when i put WHERE title_id it changes and only shows the students who have attended the class. I don't see any condition with "title_id" in it. Quote Link to comment https://forums.phpfreaks.com/topic/245544-mysql-left-join-help/#findComment-1261461 Share on other sites More sharing options...
sportsreport2 Posted August 24, 2011 Author Share Posted August 24, 2011 I meant to say class_id not title_id. For clarification this is what my output needs to be like... So I have a page of links that have the class title and date printed, when the teacher clicks on the title/date it would go to a separate page that lists every students name and whether they attended the class or not, by saying "Attended" or "Not Attended." Then the teacher wants to be able to click on the "Attended" or "Not Attended" and be able to switch it to the other one. For example if Student A did not attend the teacher would click on "Not Attended" and it would automatically change it to "Attended" So im not sure if my database is set up wrong or what but i can't seem to figure it out. thanks for your help PS whats wrong with <? ?> why do you need the php if it all works the same? Quote Link to comment https://forums.phpfreaks.com/topic/245544-mysql-left-join-help/#findComment-1261464 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.