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// ?> Link to comment https://forums.phpfreaks.com/topic/93516-relations-query/ Share on other sites More sharing options...
revraz Posted February 28, 2008 Share Posted February 28, 2008 Use JOIN ON Link to comment https://forums.phpfreaks.com/topic/93516-relations-query/#findComment-479117 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 Link to comment https://forums.phpfreaks.com/topic/93516-relations-query/#findComment-479119 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']; } } ?> Link to comment https://forums.phpfreaks.com/topic/93516-relations-query/#findComment-479125 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.