【发布时间】:2011-12-15 20:08:51
【问题描述】:
我的网站中有一个个人消息系统,只需使用 php/sql 完成。实际上,我遇到了使用 jquery 显示它们的麻烦。数据库具有以下字段:message_id、message_from、message_to、message_topic、message_subject 和 message_status。我显示message_topic 的方式是重复以下八次:
echo '<table><tr><td>';
retrieve_msg_topic($result);
echo '</td></tr>'; //of course I won't make 8 tables!!!
调用的函数是:
function retrieve_msg_topic($result)
{
if($row = mysql_fetch_assoc($result))
{
echo $row['usernombre'];
$message_topic = stripslashes($row['message_topic']);
echo '<div id="msg'.$row['message_id'].'">';
echo $message_topic;
echo '</div>';
//this will return: <div id="msgN">message topic (title, commonly subject)</div>
}
} //end function retrieve msg topic
到目前为止,我的表格上有一个列表,其中包含发送给用户的最后八条消息。下一行保留用于分页(下一页/上一页),然后,另一行显示我从显示的列表中选择的消息,就像我们在 Outlook 中看到的那样。这是我的头痛。我的方法是调用另一个函数(8 次)并将它们全部隐藏,直到我单击其中一条消息,如下所示:
echo '<tr><td>';
retrieve_msg_content($result);
retrieve_msg_content($result); //repeat 8 times
echo '</td></tr></table>';
这次的函数是这样的:
function retrieve_msg_content($result)
{
if($row = mysql_fetch_assoc($result))
{
echo '<script type="text/javascript">
$(document).ready(function(){
$("#msg'.$row['message_id'].'").click(function(){
$(".msgs").hide(1000);
$("#'.$row['message_id'].'").show(1000);
});
});
</script>';
echo '<div class="msgs" id="'.$row['message_id'].'" style="display: none">'
.$row['message_subject'].
'</div>';
}
/* This function returns:
// <script type="text/javascript">
// $(document).ready(function(){
// $("#msgN").click(function(){
// $(".msgs").hide(1000);
// $("#N").show(1000);
// });
// });
// </script>
// <div class="msgs" id="N" style="display: none">Message subject (body of message)</div>
*/
} //end function retrieve msg content/subject
我可以简单地解释问题在于它不起作用,这是因为我做了两次if($row = mysql_fetch_assoc($result)),所以第二次它没有更多的值!
我的另一种方法是在同一个函数中同时调用 message_topic 和 message_subject,但我最终得到了一种手风琴,这不是我想要的。
我希望我已经足够清楚了。
【问题讨论】: