如何在php循环之前发送会话(变量)?

时间:2017-06-18 09:07:07

标签: php html mysqli

我用

while($row = mysqli_fetch_array($result))

打印所有sql结果。

我每行都有一个按钮...... “onclick =”Pos.action ='wantToRent.php'; Pos.submit();“> 立即向其他页面传达价值。 如果我尝试传达下一个值喜欢:

<?php $_SESSION['SID']= $row[7];?>

<input type=hidden name=SID value="<?php echo $row[7];?>">

它将受循环影响并传达表格的最后一个$ row [7] ...

如何在没有影响的情况下获得正确的行SID?

完整代码:

  <form name = "Pos" action = ""  method = "post">
  <?php 
  include('phpfile/db_connect.php');
  $sql = " SELECT * FROM product";
  $result = mysqli_query($conn,$sql); 
     while($row = mysqli_fetch_array($result)){?>
    <div class='proList'>
      <h3 class='proTitle'><a href='https://www.google.com'><?php echo $row[1];?></a></h3>
      <div class='proleft pro'><img src='' alt='abc'/></div>
      <div class='proright pro'><a class='seller protxt' href='https://www.google.com'> <?php echo $row[2];?> </a>
        <div class='proPri protxt'> <?php echo $row[3];?> </div>
        <div class='proTim protxt'> <?php echo $row[4];?> </div>
        <div class='proPosi protxt'> <?php echo $row[5];?> </div>
        <div class='proDeti protxt'><?php $row[6];?> </div><br/>
        <button name="iwantR" value="<?php echo $row[0];?>" onclick="Pos.action='wantToRent.php';Pos.submit();">rent</button>
        <?php $_SESSION['SID']= $row[7];?> //where I try send out SID without loop influence.
      </div>
    </div>
  <?php
  }
  ?>
  </form>

0 个答案:

没有答案