我正在创建一个类Web页面,允许您通过单击与该类关联的链接来查看类详细信息。我有一个数据库,里面装有班级,注册的学生以及指定的教授。下面我在每个循环中有一个查询,从结果中创建一个表,但是我想创建指向该类页面的条目URL。例如:“localhost / class?class_id = cs120”。我不能只在下面添加一个链接,并将其参数化为cs120,因为所有链接都会去那里。我对SQLITE3,PHP和HTML的理解是有限的,下面是我对此页面的代码。
<!DOCTYPE html>
<?php include("secure.php") ?>
<html lang= "en">
<head>
<title> Class Index </title>
<meta charset= "utf-8" />
<link rel="stylesheet" href="class_coverpage.css" />
</head>
<?php
//echo("Hello Retrieving Table");
$username = $_SESSION['user'];
//echo 'Hello: ' . $username;
$classquery = "SELECT DISTINCT Classes.Class_id, Classes.Section_id ,Classes.className, Classes.Subject, Classes.Location FROM Classes,StudentClasses,Students WHERE StudentClasses.Class_id = Classes.Class_id AND StudentClasses.Student_id = Students.Student_id AND StudentClasses.Section_id = Classes.Section_id AND Students.Username = '$username'; ";
//$teacherquery = "SELECT TeacherClasses.Teacher_id, TeacherClasses.Class_id FROM TeacherClasses";
//echo("Trimming Query");
trim($classquery);
//echo("Stripping Slashes");
$classquery = stripslashes($classquery);
//echo("Setting up Query");
$results = $db->query($classquery);
if (!$results){
echo("<h2>Error: The query could not be executed.</h2>");
$error = $db->lastErrorMsg();
echo("<p>$error<p>");
exit;
}
echo "<table><tr>";
echo "<td>Course ID:</td>";
echo "<td>Section ID:</td>";
echo "<td>Subject:</td>";
echo "<td>Location:</td></tr>";
echo("<tr>");
for($i=0;$i<$num_cols;$i++){
$head = $results->columnName($i);
echo("<th>$head</th>");
}
echo ("</tr>");
// Write rows into table
$ct = 0;
while ($row = $results->fetchArray(SQLITE3_ASSOC)) {
echo ("<tr>");
foreach($row as $v){
// I want to Make this section down here create a link hopefully.
//echo ("<td><a href='class_detail.php?Class_id=$row['id']'> $v </a></td>");
}
$ct = $ct + 1;
echo ("</tr>");
}
echo
("</table>");
?>