我正在尝试创建一个隐藏的按钮 消息表格&单击提交按钮后也会隐藏表单 使用jquery。此按钮与结果一起使用 一个php for()循环嵌入while()循环中,选择&安排 来自我的数据库的信息,所以while()的每一个结果 loop下面有messagebutton。 现在,我的问题是,在设置了所有循环和jquery代码之后, 一切都有效,除了消息按钮适用于所有 点击时的同一时间结果,这不是我想要的。 我需要按钮以这样的方式单独工作 点击循环结果下的按钮只有1个表格向下滑动 循环结果,如果在另一个结果下单击另一个消息按钮,则任何打开 表单关闭,新表单打开。 总之,我需要按钮为每个循环结果独立工作。 这是我使用的代码没有给我想要的结果。 PLS 帮助...
<?php
session_start();
include("databaselogin.inc");
mysql_select_db($database,$cxn);
$query="SELECT * from table1";
$result=mysql_query($query,$cxn) or die ("Couldn't execute query.". mysql_error());
$section=$_POST['section'];
?>
.
.
.
.
.
<script type="text/javascript" src="../jquery-1.3.2-vsdoc2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("div#show1").hide();
$("button#show2").click(function(){
$("div#show1").toggle(500);
});
$("a#show3").click(function(){
$("div#show1").hide(500);
});
});
</script>
<?php
while ($row=mysql_fetch_array($result))
{
$query1="SELECT * from table2 WHERE Email='$row[Email]'";
$result1=mysql_query($query1,$cxn) or die ("Couldn't execute query.". mysql_error());
$row1=mysql_fetch_array($result1);
for ($i=1; $i<=3; $i++)
{
if ($row['section1'."$i"]=="$section")
{
echo '<table height="130" width="220" border="1" style="border:thin"><tr height="104"><td width="60" valign="top" align="center">';
echo '<center>';
echo '<div style="line-height:80%">';
echo '<img border="1" src="';
echo $row['image'."$i"];
echo '"width="80" alt="Your Name" height="78">';
echo '</center>';
echo '<font face="Comic Sans MS, Colonna MT, Juice ITC" size="2" color="#9900CC">';
echo $row['section2'."$i"];
echo '</font>';
echo '</div>';
echo '</td><td width="184" align="center" valign="top"><table cellpadding="0" cellspacing="0"><tr><td bgcolor="#9900CC" width="174"><center><b><font face="Comic Sans MS, Colonna MT, Juice ITC" size="3" color="#ffffff">DESCRIPTION</font></b></center></td></tr><tr><td align="left" valign="top">';
echo '<font face="Comic Sans MS, Colonna MT, Juice ITC" size="2" color="#9900CC">';
echo $row['section3'."$i"];
echo '</font>';
echo '</td></tr></table><tr height="50" bgcolor="#9900CC"><td colspan="2" bgcolor="#ffffff">';
echo '<div style="line-height:80%">';
echo '<font face="Comic Sans MS, Colonna MT, Juice ITC" size="2" color="#9900CC">';
echo $row1['port1'];
echo '</font>';
echo '<br />';
echo '<font face="Comic Sans MS, Colonna MT, Juice ITC" size="1" color="#9900CC"><span style="white-space:pre">';
echo $row1['port2'];
echo ' PRICE: ';
echo $row['section4'."$i"];
echo '</span>';
echo '<br /><span style="white-space:pre">';
echo $row1['port3'];
echo ' ';
echo $row['section5'."$i"];
echo '</span></font>';
echo '</div>';
echo '</td></tr>';
echo '<tr height="10" bgcolor="#9900CC"><td colspan="2" bgcolor="#FDF4FD" style="border:none; line-height:30%" valign="top">';
echo '<span style="white-space:pre"><button id="show2" style="border:none"><font face="Comic Sans MS, Colonna MT, Juice ITC" size="1" color="#9900CC">message</font></button>';
echo '<font face="Comic Sans MS, Colonna MT, Juice ITC" size="1" color="#9900CC"> | </font>';
echo '<font face="Comic Sans MS, Colonna MT, Juice ITC" size="1" color="#9900CC">comment</font></span>';
echo '</td></tr></table>';
?>
<!-- START DIV that contains the Private Message form -->
<div id="show1">
<table>
<form method="post" action="">
<font face="Comic Sans MS, Colonna MT, Juice ITC" size="2" color="#9900CC">Send a Message to <strong><?php echo $row1['port1']; ?></strong></font>
<tr><td align="right" width="80"><font face="Comic Sans MS, Colonna MT, Juice ITC" size="2" color="#9900CC">First Name:</font></td><td width="200"><input name="sender" type="text" maxlength="30" style="width:100%" /></td></tr>
<tr><td align="right" width="80"><font face="Comic Sans MS, Colonna MT, Juice ITC" size="2" color="#9900CC">Subject:</font></td><td width="200"><input name="pmSubject" id="pmSubject" type="text" maxlength="64" style="width:100%" /></td></tr>
<tr><td align="right" width="80" valign="top"><font face="Comic Sans MS, Colonna MT, Juice ITC" size="2" color="#9900CC">Message:</font></td><td width="200"><textarea name="pmTextArea" id="pmTextArea" rows="5" style="width:100%"></textarea></td></tr>
<input name="pm_rec_name" id="pm_rec_name" type="hidden" value="<?php echo port4; ?>" />
<span id="PMStatus" style="color:#F00;"></span>
<br /><tr><td colspan="2"><span style="white-space:pre"><input name="pmSubmit" type="submit" value="Send" /><font face="Comic Sans MS, Colonna MT, Juice ITC" size="2" color="#9900CC"> or <a href="#" id="show3">Close</a></font></span>
<span id="pmFormProcessGif" style="display:none;"><img src="../loading.gif" width="28" height="10" alt="Loading" /></span></td></tr></form>
</table>
</div>
<!-- END DIV that contains the Private Message form -->
<?php
echo '<br />';
}
}
}
?>
答案 0 :(得分:0)
好吧我没有测试过这个,但我做的是将javascript放在循环中并每次重命名它以及除法,按钮和链接。如果你设计它们,你需要添加一个类并重新设置它们。
<?php
session_start();
include("databaselogin.inc");
mysql_select_db($database,$cxn);
$query="SELECT * from table1";
$result=mysql_query($query,$cxn) or die ("Couldn't execute query.". mysql_error());
$section=$_POST['section'];
?>
<script type="text/javascript" src="../jquery-1.3.2-vsdoc2.js"></script>
<?php
while ($row=mysql_fetch_array($result))
{
$query1="SELECT * from table2 WHERE Email='$row[Email]'";
$result1=mysql_query($query1,$cxn) or die ("Couldn't execute query.". mysql_error());
$row1=mysql_fetch_array($result1);
for ($i=1; $i<=3; $i++)
{
$show1 = rand(1, 1000);
$show2 = rand(1001, 2000);
$show3 = rand(2001, 3000);
?>
<script type="text/javascript">
$(document).ready(function(){
$("div#<?PHP echo $show1; ?>").hide();
$("button#<?PHP echo $show2; ?>").click(function(){
$("div#<?PHP echo $show1; ?>").toggle(500);
});
$("a#<?PHP echo $show3; ?>").click(function(){
$("div#<?PHP echo $show1; ?>").hide(500);
});
});
</script>
<?PHP
if ($row['section1'."$i"]=="$section")
{
echo '<table height="130" width="220" border="1" style="border:thin"><tr height="104"><td width="60" valign="top" align="center">';
echo '<center>';
echo '<div style="line-height:80%">';
echo '<img border="1" src="';
echo $row['image'."$i"];
echo '"width="80" alt="Your Name" height="78">';
echo '</center>';
echo '<font face="Comic Sans MS, Colonna MT, Juice ITC" size="2" color="#9900CC">';
echo $row['section2'."$i"];
echo '</font>';
echo '</div>';
echo '</td><td width="184" align="center" valign="top"><table cellpadding="0" cellspacing="0"><tr><td bgcolor="#9900CC" width="174"><center><b><font face="Comic Sans MS, Colonna MT, Juice ITC" size="3" color="#ffffff">DESCRIPTION</font></b></center></td></tr><tr><td align="left" valign="top">';
echo '<font face="Comic Sans MS, Colonna MT, Juice ITC" size="2" color="#9900CC">';
echo $row['section3'."$i"];
echo '</font>';
echo '</td></tr></table><tr height="50" bgcolor="#9900CC"><td colspan="2" bgcolor="#ffffff">';
echo '<div style="line-height:80%">';
echo '<font face="Comic Sans MS, Colonna MT, Juice ITC" size="2" color="#9900CC">';
echo $row1['port1'];
echo '</font>';
echo '<br />';
echo '<font face="Comic Sans MS, Colonna MT, Juice ITC" size="1" color="#9900CC"><span style="white-space:pre">';
echo $row1['port2'];
echo ' PRICE: ';
echo $row['section4'."$i"];
echo '</span>';
echo '<br /><span style="white-space:pre">';
echo $row1['port3'];
echo ' ';
echo $row['section5'."$i"];
echo '</span></font>';
echo '</div>';
echo '</td></tr>';
echo '<tr height="10" bgcolor="#9900CC"><td colspan="2" bgcolor="#FDF4FD" style="border:none; line-height:30%" valign="top">';
echo '<span style="white-space:pre"><button id="'.$show2.'" style="border:none"><font face="Comic Sans MS, Colonna MT, Juice ITC" size="1" color="#9900CC">message</font></button>';
echo '<font face="Comic Sans MS, Colonna MT, Juice ITC" size="1" color="#9900CC"> | </font>';
echo '<font face="Comic Sans MS, Colonna MT, Juice ITC" size="1" color="#9900CC">comment</font></span>';
echo '</td></tr></table>';
?>
<!-- START DIV that contains the Private Message form -->
<div id="<?PHP echo $show1; ?>">
<table>
<form method="post" action="">
<font face="Comic Sans MS, Colonna MT, Juice ITC" size="2" color="#9900CC">Send a Message to <strong><?php echo $row1['port1']; ?></strong></font>
<tr><td align="right" width="80"><font face="Comic Sans MS, Colonna MT, Juice ITC" size="2" color="#9900CC">First Name:</font></td><td width="200"><input name="sender" type="text" maxlength="30" style="width:100%" /></td></tr>
<tr><td align="right" width="80"><font face="Comic Sans MS, Colonna MT, Juice ITC" size="2" color="#9900CC">Subject:</font></td><td width="200"><input name="pmSubject" id="pmSubject" type="text" maxlength="64" style="width:100%" /></td></tr>
<tr><td align="right" width="80" valign="top"><font face="Comic Sans MS, Colonna MT, Juice ITC" size="2" color="#9900CC">Message:</font></td><td width="200"><textarea name="pmTextArea" id="pmTextArea" rows="5" style="width:100%"></textarea></td></tr>
<input name="pm_rec_name" id="pm_rec_name" type="hidden" value="<?php echo port4; ?>" />
<span id="PMStatus" style="color:#F00;"></span>
<br /><tr><td colspan="2"><span style="white-space:pre"><input name="pmSubmit" type="submit" value="Send" /><font face="Comic Sans MS, Colonna MT, Juice ITC" size="2" color="#9900CC"> or <a href="#" id="<?PHP echo $show3; ?>">Close</a></font></span>
<span id="pmFormProcessGif" style="display:none;"><img src="../loading.gif" width="28" height="10" alt="Loading" /></span></td></tr></form>
</table>
</div>
<!-- END DIV that contains the Private Message form -->
<?php
echo '<br />';
}
}
}
?>