Pulling data from a database according to field value
Posted: Mon Apr 11, 2011 11:44 pm
I have 3 tables of which 1 is a relations table between the other 2. What I'm trying to do is make a table that shows courses using table A (this works) and the students registered for that specific course from table B. My problem is that not all my students are showing (it seems to only show 1 student per course) but the few that do show are in the correct places.
Any advice would be appreciated.
Code: Select all
function list_students_per_course() {
global $connection;
$qry = "SELECT cid FROM course_student";
$res = mysql_query($qry);
$ary = mysql_fetch_array($res);
$cid = $ary['cid'];
$query = "SELECT sno FROM course_student WHERE cid=".$_GET['cid'];
$result = mysql_query($query);
while ($array = mysql_fetch_array($result)) {
$sno = $array['sno'];
}
$query2 = "SELECT sno, fname, sname FROM student WHERE sno = $sno";
$result2 = mysql_query($query2);
while ($row = mysql_fetch_array($result2)) {
$sno2 = $row['sno'];
$fname = $row['fname'];
$sname = $row['sname'];
echo "<tr>";
echo "<td width = '33%' align = 'center'>".$row['sno']."</td>";
echo "<td width = '33%' align = 'center'>".$row['fname']." ".$row['sname']."</td>";
}
}