0

我正在尝试将我的数据库结果(用户)转换为可点击的链接,然后将显示有关所选用户的更多信息。现在我正在使用 $_GET,但用户 ID 将显示在地址栏中。有没有办法我可以发布它?

目前,我有:

//fetch and display the results in table
while ($row = mysqli_fetch_array($result, MYSQL_ASSOC)){
  $name = $row["name"];
  $id = $row["id"];

//prepare user for GET statement  
echo ' <div><a href=mylink.php?id="'.htmlspecialchars($row['id']).'">'.$row['name'].'</a></div> ';} 

这显示:www.mylink.php?=id"12345"

我不想显示 ID。那么纠正这个问题的最佳方法是什么?谢谢

4

2 回答 2

0

您可以用小表格替换所有超链接:

<form action='mylink.php' method=post>
  <input type=hidden value='$id'>
  <input class='post_link' type=submit value='$name'>
</form>

CSS 将帮助您重新设置链接等按钮的样式:

.post_link {
    background-color: transparent;
    border: none;
    border-bottom: solid 1px blue;
    color: blue;
    display: inline;
    height: ...;
    etc
}

打开新选项卡将无法再次使用,并且悬停时您将看不到任何状态栏。

于 2013-10-27T03:05:37.850 回答
0

您必须创建一个表单和一个脚本来发布您的数据。像这样的东西:

<?php
while ($row = mysqli_fetch_array($result, MYSQL_ASSOC)){
  $name = $row["name"];
  $id = $row["id"];

//prepare user for GET statement  
echo "<div><a href=\"#\" onclick='javascript:postIt(".htmlspecialchars($row['id']).");'>".$row['name']."</a></div> ";
}

?>
<script>
 function postIt(value){
   document.forms[0].id.value = value;
   document.forms[0].submit();
 }
</script>
<form name="blah" action="mylink.php" method="post">
<input type="hidden" name="id">
</form>
于 2013-10-27T03:09:09.727 回答