gpt4 book ai didi

php - 为什么只显示最后输入的消息

转载 作者:行者123 更新时间:2023-11-29 06:38:54 25 4
gpt4 key购买 nike


谁能帮我解决我的个人资料中有一条用户消息,它只显示最后一条消息,我该如何显示该用户的所有消息。

下面是我已有的代码:

<?php 
$message_list = mysql_query("SELECT * FROM `messages`");
while($get_message = mysql_fetch_array($message_list)) {
$message_subject = $get_message['subject'];
$message_body = $get_message['body'];
$message_from = $get_message['from_user'];
$message_date = $get_message['date'];
$message_to = $get_message['to_user'];
}
if($message_to === $user_data['username']) {


echo
'
<center>
<table border="2" bordercolor="" style="background-color:" width="85%" cellpadding="3" cellspacing="3">
<tr>
<td width="15%"><center>From</center></td>
<td width="20%"><center>Date / Time</center></td>
<td><center>Message</center></td>
<td width="15%"><center>Reply</center></td>
<td width="7%"><center>Delete</center></td>
</tr>
</table>
</center>';
echo
'
<center>
<table border="1" bordercolor="" style="background-color:" width="85%" height="35px" cellpadding="3" cellspacing="3">
<tr>
<td width="15%"><center>'. $message_from .'</center></td>
<td width="20%"><center>'. $message_date .'</center></td>
<td><center><br>'. $message_body .'<br></center><br></td>
<td width="15%"><center>Reply</center></td>
<td width="7%"><center><form><input type="checkbox" name="delete"></form></center></td>
</tr>
</table>
</center>';
} else {
echo '<center>you have no messages</center>';
}
?>

它的所有显示是最后输入的消息而不是全部。

最佳答案

问题是 while 循环你提前结束了,试试这个代码而不是你的

    <?php 
$message_list = mysql_query("SELECT * FROM `messages`");
while($get_message = mysql_fetch_array($message_list)) {
$message_subject = $get_message['subject'];
$message_body = $get_message['body'];
$message_from = $get_message['from_user'];
$message_date = $get_message['date'];
$message_to = $get_message['to_user'];

if($message_to === $user_data['username']) {


echo
'
<center>
<table border="2" bordercolor="" style="background-color:" width="85%" cellpadding="3" cellspacing="3">
<tr>
<td width="15%"><center>From</center></td>
<td width="20%"><center>Date / Time</center></td>
<td><center>Message</center></td>
<td width="15%"><center>Reply</center></td>
<td width="7%"><center>Delete</center></td>
</tr>
</table>
</center>';
echo
'
<center>
<table border="1" bordercolor="" style="background-color:" width="85%" height="35px" cellpadding="3" cellspacing="3">
<tr>
<td width="15%"><center>'. $message_from .'</center></td>
<td width="20%"><center>'. $message_date .'</center></td>
<td><center><br>'. $message_body .'<br></center><br></td>
<td width="15%"><center>Reply</center></td>
<td width="7%"><center><form><input type="checkbox" name="delete"></form></center></td>
</tr>
</table>
</center>';
} else {
echo '<center>you have no messages</center>';
}
}
?>

关于php - 为什么只显示最后输入的消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22802642/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com