Jquery 使用modal在while循环中发布或获取PHP值

Jquery 使用modal在while循环中发布或获取PHP值,jquery,post,mysqli,while-loop,modal-dialog,Jquery,Post,Mysqli,While Loop,Modal Dialog,下面是在while循环表中显示的用户的mysqli查询,其中一列显示名字,另一列显示可单击链接。我想单击使用javascript或类似jquery的其他东西打开模式覆盖屏幕,然后单击消息按钮,将PHP值发布或发送到同一页面或其他页面。下面的问题是,只有第一个$id_朋友显示在模态中,这取决于它是在循环中还是在循环外。请帮助找到安全、方便地检索这些值的最佳方法 <?php while($row = mysqli_fetch_array($result)) { ?> $id_fri

下面是在while循环表中显示的用户的mysqli查询,其中一列显示名字,另一列显示可单击链接。我想单击使用javascript或类似jquery的其他东西打开模式覆盖屏幕,然后单击消息按钮,将PHP值发布或发送到同一页面或其他页面。下面的问题是,只有第一个$id_朋友显示在模态中,这取决于它是在循环中还是在循环外。请帮助找到安全、方便地检索这些值的最佳方法

<?php while($row = mysqli_fetch_array($result)) {  ?>

 $id_friend = $row['id_friend'];

 $firstName = $row['firstName'];


<table>
<tr>
<td><a><?php echo $firstName;  ?></a></td>
<td>

<!-- opens modal -->

<a href="#" id="<?php echo $row['friend_id'];?>" onclick="show(this.id)" >open </a>

<!-- modal -->

<div id="myNav2" class="overlay2">

<a href="javascript:void(0)" class="closebtn2" 
onclick="closeNav233()">&times;</a>

  <div class="overlay2-content">
     <div>
<form  action="getuser2.php" method="POST">
<button  name="friend_id" value="<?php echo $id_friend; ?>" 
type="submit">MESSAGE</button>
<input  class="friend_id" type="hidden" name="friend_id" value="<?php echo 
$id_friend; ?>" >
</form>
     </div>
  </div>
</div>

</td>
</tr>

<?php
 } //end of while loop
?> 

</table>

<script>
function show() {

document.getElementById("myNav2").style.width = "100%"; //opens modal

option = $(this).attr('id');
console.log(option ); //to check clicked id is Ok

$.ajax({
    url: 'testmodal.php',
    type: 'GET',
    data: {option : id},
    success: function(data) {
    alert($(this).data('id'));
    document.getElementById('myNav2').innerHTML =data;
    }
});

}

</script>

<style>
body {
font-family: 'Lato', sans-serif;
}

.overlay2 {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0, 0.9);
overflow-x: hidden;
transition: 0.5s;
}

.overlay2-content {
position: relative;
top: 25%;
width: 100%;
text-align: center;
margin-top: 30px;
}

.overlay2 a {
padding: 8px;
text-decoration: none;
font-size: 36px;
color: #818181;
display: block;
transition: 0.3s;
}

.overlay2 a:hover, .overlay2 a:focus {
color: #f1f1f1;
}

.overlay2 .closebtn2 {
position: absolute;
top: 20px;
right: 45px;
font-size: 60px;
}

@media screen and (max-height: 450px) {
  .overlay2 a {font-size: 20px}
  .overlay2 .closebtn2 {
  font-size: 40px;
   top: 15px;
  right: 35px;
 }
 }
</style>

<script>

function closeNav233() {
document.getElementById("myNav2").style.width = "0%";
}
</script>

$id_-friend=$row['id_-friend'];
$firstName=$row['firstName'];

这就是如何获取行中的列您在使用first_name和friend_id时使用了一些以前初始化的数据

谢谢,但是无论我使用$row['friend_id']还是初始化数据,如$friend_id,它都只会在模式覆盖中回显第一个或最后一个$friend_id,这取决于它是在循环中还是在外。在页面和表格上可以很好地工作。我想我需要Ajax。我能看一个这样的例子吗,这样我就可以理解了,我觉得可能是我没有正确理解这个问题
while($row = mysqli_fetch_array($result))  
{
$row['post_id'].$row['post_title'].$row['content']; 

}