dongyuanliao6204 2017-06-18 09:07
浏览 28

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

I use

while($row = mysqli_fetch_array($result))

to print all sql result.

and I have a button for each row... " onclick="Pos.action='wantToRent.php';Pos.submit();"> to convey value immediately to other page. and if I try convey next value likes:

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

or

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

it will be influence by loop and convey the last value $row[7] of table...

how I get the correct SID of row without influence?

full code:

  <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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
    • ¥20 易康econgnition精度验证
    • ¥15 msix packaging tool打包问题
    • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
    • ¥15 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致