dongwei1895 2018-05-23 17:48
浏览 35

从数据库结果制作的表中创建可点击链接

I'm making a class web-page that allow you to view class details by clicking a link associated with the class. I have a database loaded with classes,enrolled students as well as the assigned professor. Below I have the query in a for each loop creating a table from the results however I want to make the entries urls that direct to that class page. For example: "localhost/class?class_id=cs120". I can't just add a link below and have it parameterized to cs120 as all links would just go there. My understanding of SQLITE3, PHP and HTML is limited, Below is my code for this page.

    <!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>");

?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 BP神经网络控制倒立摆
    • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
    • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
    • ¥30 Unity接入微信SDK 无法开启摄像头
    • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
    • ¥20 cad图纸,chx-3六轴码垛机器人
    • ¥15 移动摄像头专网需要解vlan
    • ¥20 access多表提取相同字段数据并合并
    • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
    • ¥20 Java-Oj-桌布的计算