我的网站上有一个消息系统,我正在尝试将消息分组到对话中,类似于 Facebook 的做法。以下是我正在使用的 PHP 代码:
<form name="myform" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
<a href="#new_message" data-toggle="modal" class="btn btn-primary pull-right">New Message </a> <input type="submit" name="deleteBtn" class="btn btn-danger pull-right" id="deleteBtn" value="Delete Selected" />
<br /><br /> <?php
///////////End take away///////////////////////
// SQL to gather their entire PM list
$sql = mysqli_query($db_conx,"SELECT * FROM (SELECT * FROM private_messages WHERE to_id='$my_id' AND recipientDelete='0' ORDER BY time_sent DESC) AS tmp_table GROUP BY LOWER(from_id)");
while($row = mysqli_fetch_array($sql, MYSQLI_ASSOC)){
$item_date = $row["time_sent"];
$convertedTime = ($myObject -> convert_datetime($item_date));
$date = ($myObject -> makeAgo($convertedTime));
//$date = strftime("%b %d, %Y",strtotime($row['time_sent']));
if($row['opened'] == "0"){
$textWeight = 'msgDefault';
} else {
$textWeight = 'msgRead';
}
$fr_id = $row['from_id'];
// SQL - Collect username for sender inside loop
$ret = mysqli_query($db_conx,"SELECT id, username, firstname, lastname FROM bs_mem_base389 WHERE id='$fr_id' LIMIT 1");
while($raw = mysqli_fetch_array($ret, MYSQLI_ASSOC)){ $Sid = $raw['id']; $Sname = $raw['username']; $Sfirst = $raw['firstname']; $Slast = $raw['lastname'];
if ($Sfirst != "") {$Sname = "$Sfirst $Slast";} } //}
?>
<a href="message.php?id=<?php echo $fr_id; ?>" class="<?php echo $textWeight; ?>">
<p class="pull-right"><?php echo $date; ?> <input type="checkbox" name="cb<?php echo $row['id']; ?>" id="cb" value="<?php echo $row['id']; ?>" /></p>
<h4><?php echo $Sname; ?></h4>
<p><?php echo stripslashes(wordwrap(nl2br($row['message']), 54, "\n", true)); ?></p></a>
<?php
}// Close Main while loop
?></form>
将它们组合在一起很好,但它们的顺序不正确。他们都乱七八糟的。关于如何订购它们以使带有最新消息的 convo 排在第一位的任何想法?