duanji2014 2014-04-14 22:13
浏览 16
已采纳

在循环中使用参数发送href

<!doctype html>
<html>
<head>
<title>Main Page</title>
</head>
<?php
session_start();
?>
<form action="new_question.php" method="post">
<input type="hidden" name="sid" value="<?php echo $_SESSION['username']?>">
<input type="submit" value="New Question">
</form>
<?php
include ("connection.php");

$result = mysqli_query($con,"SELECT * FROM question_table");

while($row = mysqli_fetch_array($result))
  {
  echo "<a href=\"http://localhost/project/question.php\">" . $row['question'] . $row['q_id'] . "</a>";
  echo "<br>";
  }
?>
<body>
</body>
</html>

I have 5 question in my database each with a id. this page prints them as a link in loop. upon clicking any of the link it goes to "question.php" file. there i want to echo the question from the database that was clicked previously. the problem is in "question.php" file how do i find out which link was clicked among thus 5. should i send a parameter along with the link? how the parameter will change in each loop? how do i do it in this page? if i do send a parameter with the link how do i receive it in the "question.php" file?

  • 写回答

1条回答 默认 最新

  • dongyan6503 2014-04-14 22:19
    关注

    Echo the id as a parameter on the anchor. We can also remove the id from the anchor text since it's not needed there anymore.

    while($row = mysqli_fetch_array($result))
    {
      echo '<a href="http://localhost/project/question.php?id=' . $row['q_id'] . '">' . $row['question'] . '</a><br>';
    }
    

    And then in question.php do $_GET['id']

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源