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']

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

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探