我正在尝试创建一个按钮来显示隐藏的消息表单并在使用 jquery 单击提交按钮后隐藏表单。此按钮与嵌入在 while() 循环中的 php for() 循环的结果一起使用,该循环从我的数据库中选择和排列信息,因此 while() 循环的每个结果都有其下方的消息按钮。现在,我的问题是,在设置了所有循环和 jquery 代码之后,一切正常,除了消息按钮在单击时适用于所有结果,这不是我想要的。我需要按钮单独工作,这样当单击循环结果下的按钮时,只有一个表单会在循环结果下向下滑动,如果在另一个结果下单击另一个消息按钮,则任何打开的表单都会关闭,新的表单会打开. 总之,我需要按钮为每个循环结果独立工作。这是我使用的代码,但没有给我想要的结果。请帮助...
<?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 />';
}
}
}
?>