duanfu4446 2015-03-06 06:00
浏览 55
已采纳

如何使用SQL查询生成的按钮获取id / name onclick?

I am creating a table from a MySQL database. Currently, I can manually enter the Course ID, then click 'select' to display a roster based on the Course ID entered.

However, I would like to streamline this with buttons on the right side of the table after each row. What is the best way to do this? I can provide a screenshot, but I still need more reputation.

So the code for generating this table is as follows.

<?php
// Connection information to database has been removed. 

// $Row[1] - first name of faculty
// $Row[2] - last name of faculty
// $fieldRow[0] - course ID
// $fieldRow[1] - course name
// $fieldRow[2] - course year
// $fieldRow[3] - number of units

echo "<table>
<caption>....for " . $Row[1] . " " . $Row[2] . "</caption>
<tr>
  <th>Course ID</th>
  <th>Course Name</th>
  <th>Course Year</th>
  <th>Units</th>
</tr>";
while ($fieldRow = mysqli_fetch_row($result2))
{
    echo "<tr><td>" . $fieldRow[0] . "</td>
    <td>" . $fieldRow[1] . "</td>
    <td>" . $fieldRow[2] . "</td>
    <td>" . $fieldRow[3] . "</td>
    <td><button name='" . $fieldRow[0] . "'>Select</button></td>
    </tr>";
}
echo "</table>";
?>

<form method="get" action="class.php">
  <p>Enter Course ID
    <input autofocus="autofocus" tabindex="1" type="text" maxlength="5" name="classSelect" title="Enter Class Number" />
  </p>
  <p>
    <button tabindex="2" type="submit">Select</button>
  </p>
</form>

Thanks for looking at this!

  • 写回答

2条回答 默认 最新

  • dongyong8098 2015-03-06 06:10
    关注

    You could have something like

    if(isset($_GET['id'])
    {
      $course_id = intval($_GET['id']);
      // Do your query against the course id.
    }
    
     while ($fieldRow = mysqli_fetch_row($result2))
        {
          echo "<tr><td>" . $fieldRow[0] . "</td>
          <td>" . $fieldRow[1] . "</td>
          <td>" . $fieldRow[2] . "</td>
          <td>" . $fieldRow[3] . "</td>
          <td><a href='" . ?id=$fieldRow[0] . "'>Select</a></td>
          </tr>";
        }
        echo "</table>";
        ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂