Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php jquery弹出消息框在while循环中工作_Php_Mysql - Fatal编程技术网

Php jquery弹出消息框在while循环中工作

Php jquery弹出消息框在while循环中工作,php,mysql,Php,Mysql,我在while循环中有一个弹出消息框,但是在弹出地址字段中,所有条目都显示相同的地址 谁能告诉我我做错了什么 Html Jquery脚本 在表格的每一行中显示相同地址的弹出窗口问题是,您在弹出窗口中为每个div使用相同的ID。因此,无论您调用什么代码来打开弹出窗口,它都会打开第一个弹出窗口。你需要这样的东西: <script type="text/javascript"> $(document).ready(function() { $('.button').click(fu

我在while循环中有一个弹出消息框,但是在弹出地址字段中,所有条目都显示相同的地址

谁能告诉我我做错了什么

Html Jquery脚本


在表格的每一行中显示相同地址的弹出窗口问题是,您在弹出窗口中为每个div使用相同的ID。因此,无论您调用什么代码来打开弹出窗口,它都会打开第一个弹出窗口。你需要这样的东西:

<script type="text/javascript">
$(document).ready(function() {
    $('.button').click(function(e) { 
        id = $(this).attr('id').substr(3);
        //alert(id); //uncomment this line to check ID's are coming through fine.
        $('#modal' + id).reveal({ 
            animation: 'fade',                   
            animationspeed: 600,                       
            closeonbackgroundclick: true,              
            dismissmodalclass: 'close'   
        });
    return false;
    });
});
</script>

<table>
<?php
$i = 0;
$query1=mysql_query("select * from customers order by id desc");
while($row1=mysql_fetch_array($result))
{
?>
<tr>
<td><div align="center"><?php echo $row1['firstname']; ?></div></td>
<td><div align="center"><?php echo $row1['lastname']; ?></div></td>
<td><div align="center"><?php echo $row1['dob']; ?></div></td>
<td><div align="center"><?php echo $row1['email']; ?></div></td>
<td><div align="center"><a href="#" id="btn<?php echo $i; ?>" class="button">Address</a></div></td>
<td><div align="center"><?php echo $row1['phone']; ?></div></td>
<td><div align="center"><?php echo $row1['country']; ?></div></td>
<td><div align="center"><?php echo $row1['city']; ?></div></td>
</tr>


<Popup Start> 

<div class="modal" id="modal<?php echo $i++; ?>">
<div class="heading">
Sign Up! Customer's Address
</div>
<div class="content">
<p><?php echo $row1['address']; ?></p>
</div>
</div>

<Popup End>

<?php }?>
</table>
注意另一个div从ID到Class的变化。一个页面上只能使用一次ID。如果您多次重用某个对象,它应该是一个类


而且你的标签贴错了。这是一个Javascript/HTML问题,不是PHP问题。

它没有经过测试,我需要更多的信息,除了它不起作用之外,我才能提供帮助。您在Firebug中是否收到任何错误消息?它在做什么,如果有的话?不要忘记,一旦你将ID更改为类,你就需要更新css了。我还忘了增加变量$I,我已经更新了上面的代码,请重试。如果我使用id而不是类,则button将不会打开弹出消息框。我刚刚注意到您有$'button',但button是一个类。您需要“$”按钮。单击;换一个。如果仍然不起作用,那么尝试alertid;after id=确保选择了正确的id。在检查之后,确保代码正确地输出了所有不同的modals,后面有数字。每次我都在修改我的脚本。我现在甚至为您添加了警报,但是tbh您应该能够自己进行基本调试。
<script type="text/javascript">
$(document).ready(function() {
    $('.button').click(function(e) { 
        id = $(this).attr('id').substr(3);
        //alert(id); //uncomment this line to check ID's are coming through fine.
        $('#modal' + id).reveal({ 
            animation: 'fade',                   
            animationspeed: 600,                       
            closeonbackgroundclick: true,              
            dismissmodalclass: 'close'   
        });
    return false;
    });
});
</script>

<table>
<?php
$i = 0;
$query1=mysql_query("select * from customers order by id desc");
while($row1=mysql_fetch_array($result))
{
?>
<tr>
<td><div align="center"><?php echo $row1['firstname']; ?></div></td>
<td><div align="center"><?php echo $row1['lastname']; ?></div></td>
<td><div align="center"><?php echo $row1['dob']; ?></div></td>
<td><div align="center"><?php echo $row1['email']; ?></div></td>
<td><div align="center"><a href="#" id="btn<?php echo $i; ?>" class="button">Address</a></div></td>
<td><div align="center"><?php echo $row1['phone']; ?></div></td>
<td><div align="center"><?php echo $row1['country']; ?></div></td>
<td><div align="center"><?php echo $row1['city']; ?></div></td>
</tr>


<Popup Start> 

<div class="modal" id="modal<?php echo $i++; ?>">
<div class="heading">
Sign Up! Customer's Address
</div>
<div class="content">
<p><?php echo $row1['address']; ?></p>
</div>
</div>

<Popup End>

<?php }?>
</table>