talk2toyin Posted October 13, 2012 Share Posted October 13, 2012 I need to disply each logged on pupil's result to the pupil. I have three tables(a and B). Table 'a' is related to table 'b' by c_id....while table 'b' is related to an 'id' column in a different table. I need to display a list of all the courses, and scores in table 'a' and 'b' even if a score hasn't been assigned to any of the courses. Here's my source code: $sql = "SELECT * FROM a LEFT JOIN b ON a.c_id = b.c_id WHERE b.stud_id = '$stud_id' ODERE BY a.c_code"; $res = mysql_query($sql); $nrows =mysql_num_rows($res); for($i=0;$i<$nrows;$i++) { //my output display loop goes in here. } Quote Link to comment https://forums.phpfreaks.com/topic/269431-help-on-doing-a-outer-join-on-three-tables/ Share on other sites More sharing options...
Barand Posted October 13, 2012 Share Posted October 13, 2012 We cannot see your data or results. What is your problem, apart from your mis-spelling of "ORDER"? Quote Link to comment https://forums.phpfreaks.com/topic/269431-help-on-doing-a-outer-join-on-three-tables/#findComment-1385017 Share on other sites More sharing options...
talk2toyin Posted October 13, 2012 Author Share Posted October 13, 2012 That was a typo on my side...i posted it with my phone. My problem's that, that query of mine works like an inner join. It only output fields where their values are not null. Quote Link to comment https://forums.phpfreaks.com/topic/269431-help-on-doing-a-outer-join-on-three-tables/#findComment-1385021 Share on other sites More sharing options...
talk2toyin Posted October 13, 2012 Author Share Posted October 13, 2012 My table 'a' contains two values, while table 'b' contains one value.....i need the two values of table 'a' displayed and the corresponding value of table 'b'. Quote Link to comment https://forums.phpfreaks.com/topic/269431-help-on-doing-a-outer-join-on-three-tables/#findComment-1385022 Share on other sites More sharing options...
Barand Posted October 13, 2012 Share Posted October 13, 2012 $sql = "SELECT * FROM a LEFT JOIN b ON a.c_id = b.c_id AND b.stud_id = '$stud_id' ORDER BY a.c_code"; Conditions need to be in the join when left joining a table Quote Link to comment https://forums.phpfreaks.com/topic/269431-help-on-doing-a-outer-join-on-three-tables/#findComment-1385024 Share on other sites More sharing options...
talk2toyin Posted October 13, 2012 Author Share Posted October 13, 2012 Wow! U're a life saver. It worked just fine.....thanks alot man! Quote Link to comment https://forums.phpfreaks.com/topic/269431-help-on-doing-a-outer-join-on-three-tables/#findComment-1385027 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.