cyrixware Posted February 28, 2008 Share Posted February 28, 2008 Both query are correct. i was wondering how to integrate this one this is my old query: <?php $q = "SELECT student.*, studentgrade.* FROM student, studentgrade WHERE student.SuID = studentgrade.SuID ORDER BY SuGrade DESC "; $r = mysql_query($q) or die(mysql_error()."<Br /><Br / >".$q); if(mysql_num_rows($r) >0) { $i = 0; ........................ ?> Let say i want to create a relationship between two tables and heres the new one. The problem is how to integrate or add new tables in this line of codes? (table student and studentgrade) <?php $q = "SELECT SuGrade, SuID FROM studentgrade ORDER BY SuGrade DESC"; // i just want to include the tbl student here and the primary key is the SuID// ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted February 28, 2008 Share Posted February 28, 2008 Use JOIN ON Quote Link to comment Share on other sites More sharing options...
cyrixware Posted February 28, 2008 Author Share Posted February 28, 2008 Use JOIN ON how? can you give me a little example? tnx Quote Link to comment Share on other sites More sharing options...
cyrixware Posted February 28, 2008 Author Share Posted February 28, 2008 Here is the actual code: <?php $q = "SELECT SuGrade, SuID FROM studentgrade ORDER BY SuGrade DESC"; // so let say in this line i want to included the tbl student with a primary key SuID// $r = mysql_query($q) or die(mysql_error()."<Br /><Br / >".$q); if(mysql_num_rows($r) >0){ $i = 0; echo "<table><tr><td>User</td><td>Score</td><td>Rank</td></tr>"; while($row = mysql_fetch_assoc($r)) { if($row['SuGrade'] != $score) { $i++; } echo "<tr><td>".$row['SuID']."</td><td>".$row['SuGrade']."</td><td>".$i."</td></tr>"; $score =$row['SuGrade']; } } ?> Quote Link to comment 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.