-5

我希望能够通过 $_SESSION 标签将所选主题的值发送到另一个页面,但它总是获取数据库中最后一个数据的值

$sqltpc = "SELECT * FROM forum_question";
$resulttpc = mysql_query($sqltpc) or die('Error: '.mysql_error());
while($linetpc = mysql_fetch_array($resulttpc, MYSQL_ASSOC)){
   echo "
    <tr id='trow' class='right'><input type='hidden' name='hidden' value=".$linetpc['id']." />
          <td><img src='Images/logosmallforum.png' /><a href='lentech_topic.php'>".$linetpc['id']." ".$linetpc['topic']."</a></td>
      <td><a href='#'>".$linetpc['username']."</a></td>
      <td><a href='#'>".$linetpc['view']."</a></td>
      <td><a href='#'>".$linetpc['reply']."</a></td>
    </tr>";
   }

$viewtpc = $_POST['hidden'];
$_SESSION['idset'] = $viewtpc;
4

2 回答 2

0

您需要指定hidden输入是一个数组,方法是将其写为:

<input type='hidden' name='hidden[]' value=".$linetpc['id']." />

注意到方括号了吗?$_POST['hidden']然后将是所有值的数组,而不仅仅是列表中最后一个值的字符串。

请注意,您实际上必须发布表单才能使其生效(您目前的代码表明您没有)。如果您不打算发布表单,而是将值存储在输入字段中,您只需$_SESSION['idset']在循环中添加到数组中:

$sqltpc = "SELECT * FROM forum_question";
$resulttpc = mysql_query($sqltpc) or die('Error: '.mysql_error());
while($linetpc = mysql_fetch_array($resulttpc, MYSQL_ASSOC)){

   $_SESSION['idset'][] = $linetpc['id'];

   echo "
    <tr id='trow' class='right'>
          <td><img src='Images/logosmallforum.png' /><a href='lentech_topic.php'>".$linetpc['id']." ".$linetpc['topic']."</a></td>
      <td><a href='#'>".$linetpc['username']."</a></td>
      <td><a href='#'>".$linetpc['view']."</a></td>
      <td><a href='#'>".$linetpc['reply']."</a></td>
    </tr>";
   }
于 2013-03-06T19:44:10.350 回答
0

我知道了!所需要的只是$_GET将变量的值传递到另一页。

感谢您的回复,并为我迟到的回复感到抱歉

于 2013-06-26T16:36:04.167 回答