将PHP变量传递给模式

时间:2019-03-29 07:19:31

标签: php mysql

我有一个要调用的mysql数据以显示到我的PHP表中,然后例如我单击了username01,我想调用该username01的其他列(例如password01,id01)以显示到我的模式字段中。 这是我的代码:

PHP

while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" ?> <a href="#?<?php echo $row['id']; $id; ?>" onclick="document.getElementById('id01').style.display='block'" style="width:auto;"> <?php echo "<font color='blue'>" . $row['ipaddress'] . "</font></a></td>";
echo "<td>" . $row['name'] . "</td>";

模式

<?php
include 'includes\dbconn.php';
$query = mysqli_query($conn,"SELECT * from devopstbl where id=$id");
$ipaddress = $row['ipaddress'];
$name = $row['name'];
$department = $row['department'];

?>
<div id="id01" class="modal">

  <form class="modal-content animate" method="GET" action="ipaddress.php">
    <div class="imgcontainer">
      <span onclick="document.getElementById('id01').style.display='none'" class="close" title="Exit">&times;</span>
      <img src="images/avatar.png" alt="Avatar" class="avatar">
    </div>

    <div class="container">
      <label for="ipaddress"><b>Username <?php echo $username; ?></b></label>
      <input type="text" pattern="[a-zA-Z0-9\s]+" name="username" value="<?php echo $ipaddress; ?>" required>

显然.. $ id仅获得id01,即使我单击了其他数据(如id02等),也没有获得其其他列(如username01 password01 ..)。 我想念什么吗?

1 个答案:

答案 0 :(得分:0)

将模态部分放入while循环。

while($row = mysqli_fetch_array($result))
{
  $id = $row['id'];
  $username = $row['username'];
  $ipaddress = $row['ipaddress'];
  $name = $row['name'];

  echo '<tr>
    <td>
       <a href="#?'.$id.'" onclick="document.getElementById(\'id'.$id.'\').style.display=\'block\'" style="width:auto;"><font color="blue">'.$ipaddress.'</font></a>

       <div id="id'.$id.'" class="modal">
         <form class="modal-content animate" method="GET" action="ipaddress.php">
           <div class="imgcontainer">
             <span onclick="document.getElementById(\'id'.$id.'\').style.display=\'none\'" class="close" title="Exit">&times;</span>
             <img src="images/avatar.png" alt="Avatar" class="avatar">
           </div>
           <div class="container">
             <label for="ipaddress"><b>Username '.$username.'</b></label> 
             <input type="text" pattern="[a-zA-Z0-9\s]+" name="username" value="'.$ipaddress.'" required>
           </div>
         </form>
       </div>

    </td>
    <td>'.$name.'</td>
  ';           
}