首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用modal在while循环中POST或获取PHP值

使用modal在while循环中POST或获取PHP值
EN

Stack Overflow用户
提问于 2018-05-25 06:23:29
回答 1查看 57关注 0票数 0

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

代码语言:javascript
复制
<?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>
EN

回答 1

Stack Overflow用户

发布于 2018-06-01 15:16:54

代码语言:javascript
复制
while($row = mysqli_fetch_array($result))  
{
$row['post_id'].$row['post_title'].$row['content']; 

}

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50519003

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档