【问题标题】:PHP get the value of numrows data of <td> under the condition of whilePHP在while条件下获取<td>的numrows个数据的值
【发布时间】:2013-06-27 00:57:27
【问题描述】:

我希望能够通过 $_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;

【问题讨论】:

标签: php html


【解决方案1】:

您需要指定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>";
   }

【讨论】:

  • 它仍然没有将所选变量获取到 lentech_topic.php
  • 我明白了!我所需要的只是 $_GET 将变量的值传递到另一页。感谢您的回复,很抱歉我的回复晚了
【解决方案2】:

我明白了!所需要的只是$_GET 将变量的值传送到另一页。

感谢您的回复,抱歉我的回复晚了

【讨论】:

    猜你喜欢
    • 2012-09-06
    • 2016-01-01
    • 2020-10-27
    • 1970-01-01
    • 1970-01-01
    • 2011-12-13
    • 2021-06-05
    • 2015-10-14
    相关资源
    最近更新 更多