dongshen6060 2014-02-09 09:49
浏览 65
已采纳

在PHP中调用while循环中的变量

<?php
// Create connection
$con=mysqli_connect("localhost","root","root");
mysql_select_db("test") or die( "Unable to select database");
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

 //***************************** table 1 detail ***********

$query = "SELECT * FROM fraud WHERE a_number=" . $_GET["aNun_id"];
echo "<title>" . $_GET["aNun_id"] . "</title>";         
echo "<table width='50%' border='5'>
      <tr>
    <th>Date & Time</th>
      <th>A Number</th>
      <th>B Number</th>
    <th>Status</th>
      </tr>";       

$result=mysql_query($query) or die (mysql_error());
while($row=mysql_fetch_array($result))
{
  echo "<tr>";
  echo "<td>" . $row['date'] . "</td>";
  echo "<td>" . $row['a_number'] . "</td>";
  echo "<td><a href='?bNun_id=".$row['b_number']."'>" . $row['b_number'] . "</a></td>";
  echo "<td>" . $row['status'] . "</td>";
  echo "</tr>";  
}
echo "</table>";

//***************************** table 2 detail ***********

//Here i'm trying to use bNum_id in below query    
$query = "SELECT * FROM fraud WHERE b_number=" . $_GET["bNun_id"];          
echo "<table width='50%' border='5'>
      <tr>
    <th>Date & Time</th>
      <th>A Number</th>
      <th>B Number</th>
    <th>Status</th>
      </tr>"; 

$result=mysql_query($query) or die (mysql_error());

while($row=mysql_fetch_array($result))
{
  echo "<tr>";
  echo "<td>" . $row['date'] . "</td>";
  echo "<td>" . $row['a_number'] . "</td>";
  echo "<td>" . $row['b_number'] . "</td>";
  echo "<td>" . $row['status'] . "</td>";
  echo "</tr>";  
}
echo "</table>";

//connection close
mysqli_close($con);
?>

Here in table one , I used aNun_id to get the data from another PHP file with "GET" command. In the table two, I want bNun_id to show its related data in that table. How do i call bNun _id data to the second table from table one. Pls help me..

  • 写回答

1条回答 默认 最新

  • douyicao2199 2014-02-09 10:03
    关注

    Are those two tables in the same page? If so, You need to append the bNum_id to the same query string to use both aNum_id & bNum_id.

     echo "<td><a href='?aNun_id=".$_GET["aNun_id"]."&bNun_id=".$row['b_number']."'>" . $row['b_number'] . "</a></td>";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂