首页 > 解决方案 > 生成多个表,每个表(网页)中有多个链接

问题描述

我有一个网页需要以相同的格式显示多个表格,但里面有不同的数字+在许多表格单元格内生成适当的链接。

设计:该网页将为每个学校科目显示一张表格,然后里面的单元格将显示不同的班主任在老师的指导下的表现,使用 SAT 分数、期末考试和出勤率。教师姓名和科目名称必须链接到另一个页面,该页面显示有关该特定教师/科目的更多信息。

我曾经使用 php 来生成表格,但是看到这些表格中也需要有链接,而且非常“定制”,我不知道从哪里开始。每个链接都是独一无二的,没有完全重复的。假设有 6 个科目和 5 位教师,则必须生成 36 个唯一链接。

目前我有一个 sql 表,其中包含:subject、homeroom_teacher、subject_SAT_rslt_change、sat_retake_count、Final_vs_mid、improved_students_count、出席率、missing_student_count

下面,我放了一个我想为给定主题生成的表格类型的 html 示例。

<!--subjects: math, science, literature, art, history, physical education-->
    <table>
  <tr>
<th colspan="7"<a href="allsubjects.php?subject=math" style="color: #ffffff; text-align: center;">Math</b></th>  </tr>
  <tr id="tr01">
  <td><b>  Homeroom Teacher </b> </td>
    <td><b>  Subject SAT result change </b> </td>
    <td><b>  Retake count</b>  </td>
    <td><b>  Finals vs midterm difference  </b></td>
    <td><b>  Improved students count  </b></td>
    <td><b>  Attendance rates  </b></td>
    <td><b>  Students missing class  </b></td>
  </tr>
 <tr>
    <td><a href="xyz.php?subject=math">Mrs. Xyz </td>
    <td>-1% </td>
    <td>3 </td>
    <td>+22% </td>
    <td>2 </td>
    <td>-2% </td>
    <td>5 </td>
  </tr>
 <tr>
    <td><a href="abc.php?subject=math">Mr. Abc </td>
    <td>-22% </td>
    <td>2 </td>
    <td>+1% </td>
    <td>3 </td>
    <td>-6% </td>
    <td>1 </td>
  </tr>
  <tr>
    <td><a href="msa.php?subject=math">Ms. A </td>
    <td>-2% </td>
    <td>1 </td>
    <td>+10% </td>
    <td>32 </td>
    <td>-2% </td>
    <td>0 </td>
  </tr>
</table>

php

<?php
  $mysqli = new mysqli("localhost","username","password","database");
  if($mysqli->connect_errno)
    die("Connection failed".$mysqli->connect_error);
  $query = "SELECT * FROM `table1` where subject='math';";
$query .=  "SELECT * FROM `table1` where subject='literature';";
  $query .=  "SELECT * FROM `table1` where subject='science';";

  if($mysqli->multi_query($query))
  {
    $i=0;
    do{
      $result = $mysqli->store_result();
    
      
      $finfo = $result->fetch_fields();
      $title = '';

      $table = '';
      $i=0;
      foreach($finfo as $f)
      {
        if($i!=0)
          $table = $table. "<th>".$f->name."</th>";
        $i++;
      }
      $table = $table. "</tr>";
      
      while($row = $result->fetch_assoc())
      {
        $table = $table. "<tr>";
        $j=0;
        foreach($row as $v)
        {
          if($j==0) {
            $title=$v;
          
          } else {
          $table = $table. "<td>".$v."</td>";
          }
          $j++;
        }
        $table = $table. "</tr>";
      }

      echo "<table>";
      echo "<tr><th><b>".$title."</b></th></tr>";
      echo $table;
      echo "</table>";
    }while($mysqli->more_results() && $mysqli->next_result());
  }
  
?>

SQL:

insert into table1('math','mrs.xyz','-1%',3,'+22%',2,'-2%',5);

我已经标记了 javascript 和 php,因为我需要使用它们,但是如果您知道其他语言的解决方案,也欢迎您发布它们。

标签: javascriptphphtmlmysql

解决方案


正确使用 " 双引号和单引号就是这样,

$finfo = $result->fetch_fields(); *///example variable*

echo "<a hrea='".$finfo.".php'>Link text </a> ";

another way :
<a href = "<?PHP echo $finfo;?>">Link text </a> 

推荐阅读