【发布时间】:2018-05-24 22:23:29
【问题描述】:
下面是用户的 mysqli 查询,这些查询显示在 while 循环表中,其中一列中的名字和另一列中的可点击链接。我想单击使用 javascript 或什至像 jquery 之类的其他东西的 OPEN 打开模态覆盖屏幕,然后单击将 POST 或将 PHP 值发送到同一页面或其他页面的消息按钮。下面的问题是只有第一个 $id_friend 以模态显示,这取决于它是在循环中还是在循环外。请帮助找到安全轻松地检索这些值的最佳方法。
<?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()">×</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>
【问题讨论】:
标签: jquery post mysqli while-loop modal-dialog