<?PHP
$db = mysql_connect("localhost","root","test") or die("Problem connecting");
mysql_select_db("education") or die("Problem selecting database");
$query = "SELECT * From teachers";
$result = mysql_query($query) or die ("Query failed");
//let's get the number of rows in our result so we can use it in a for loop
$numofrows = mysql_num_rows($result);
echo "<TABLE class=\"maintable\" BORDER=1 frame=box width=100% CELLPADDING=0 CELLSPACING=1 >\n";
echo "<TR bgcolor=\"lightblue\">
<TD>Teacher</TD>
</TR>\n";
for($i = 0; $i < $numofrows; $i++) {
$row = mysql_fetch_array($result); //get a row from our result set
if($i % 2) { //this means if there is a remainder
echo "<TR bgcolor=\"#CCFFCC\">\n";
} else { //if there isn't a remainder we will do the else
echo "<TR bgcolor=\"#BFD8BC\">\n";
}
echo"
<TD><a href='bymaster.php?id={$row[id]}'>".stripslashes($ row[teacher_name])."</a></TD>
\n";
echo "</TR>\n";
}
//now let's close the table and be done with it
echo "</TABLE>\n";
?>
והקוד לדף השני:
<?PHP
$db = mysql_connect("localhost","root","test") or die("Problem connecting");
mysql_select_db("education") or die("Problem selecting database");
//set a direction for the search. If none is set, we'll choose ASC
if(!isset($_GET['direction'])){
$direction = 'ASC';
}else{
$direction = $_GET['direction'];
}
//set the newdirection as the opposite to the old
if($direction=="ASC"){
$newdirection= "DESC";
}else{
$newdirection = "ASC";
}
if(isset($_GET['orderby'])){
$query = "SELECT * FROM classes, teachers, types WHERE (classes.teacher_id=teachers.id AND classes.discipline_id=classes.id AND teachers.id=$id) ORDER BY '$_GET[orderby]' $direction";
}else{
$query = "SELECT * FROM classes, teachers, types WHERE (classes.teacher_id=teachers.id AND classes.discipline_id=classes.id AND teachers.id=$id)";
}
$result = mysql_query($query) or die ("Main Query failed");
//let's get the number of rows in our result so we can use it in a for loop
$numofrows = mysql_num_rows($result);
echo "<TABLE class=\"maintable\" BORDER=1 frame=box width=100% CELLPADDING=0 CELLSPACING=1 >\n";
echo "<TR bgcolor=\"lightblue\">
<TD><a href='".$_SERVER["PHP_SELF"]."?orderby=start_date& direction=".($newdirection)."'>Start Date</a></TD>
<TD><a href='".$_SERVER["PHP_SELF"]."?orderby=title&direc tion=".($newdirection)."'>Title</a></TD>
<TD>Type</TD>
<TD>Teacher</TD>
</TR>\n";
for($i = 0; $i < $numofrows; $i++) {
$row = mysql_fetch_array($result); //get a row from our result set
if($i % 2) { //this means if there is a remainder
echo "<TR bgcolor=\"#CCFFCC\">\n";
} else { //if there isn't a remainder we will do the else
echo "<TR bgcolor=\"#BFD8BC\">\n";
}
echo"
<TD>".$row['start_date']."</TD>
<TD><a href='/showall.php?primary_index={$row[primary_ind ex]}'>".stripslashes($row[title])."</a></TD>
<TD>".$row['type_name']."</TD>
<TD>".$row['teacher_name']."</TD>
\n";
echo "</TR>\n";
}
//now let's close the table and be done with it
echo "</TABLE>\n";
mysql_free_result($result);
?>