php - How to remove duplication in the retrieval results? -
please need help beginner in php , sql, want retrieve students names registered in each level(1 or 2 or 3 or 4) code.
<form id="form1" name="form1" method="post" action=""> <table border="1" align="center" class="tftable"> <?php $lvlid = $_get['id']; $sql2 = "select * `course` acadlevel='$lvlid' "; $res2= mysql_query($sql2,$con_mark_entry); while($row2 = mysql_fetch_row($res2)) {?> <?php } ?> <tr> <th id="h7">serial no.</th> <th id="h7">student no.</th> <th id="h7">student name</th> </tr> <?php $s=1; $sql ="select student.stud_id,student.stud_name, course.title, enrollment.grade student, course, enrollment course.acadlevel ='".$_get['id'] ."' , course.code = enrollment.code , student.stud_id = enrollment.stud_id"; $res= mysql_query($sql,$con_mark_entry); while($row1 = mysql_fetch_row($res)){ ?> <tr> <td><?php echo $s?> </td> <td><?php echo $row1[0]?></td> <td id="name"><a href="report6.php?id=<?php echo $row1[1]?>"> <?php echo $row1[1]?> </td> </tr> <?php $s++; } ?> </table> my problem illustration if pupil registered in 3 course of study @ level 1 ,he appear 3 times, want remove duplication. how?
the result follow:
serial no pupil no pupil name 1 101 adam nagdy 2 101 adam nagdy 3 101 adam nagdy 4 102 shima najm
thanks in advance
use distinct keyword. removes duplicate result rows.
search "distinct" in page.
select distinct std.stud_id,std.stud_name, enr.grade -- , crs.title pupil std left outer bring together enrollment enr on std.stud_id = enr.stud_id left outer bring together course of study crs on crs.code = enr.code course.acadlevel ='your_id' and utilize join join. ;) improve joining where (even if works).
php mysql
No comments:
Post a Comment