简体   繁体   English

如果多个只显示一次,则尝试在表中显示所有不同的用户名

[英]trying to display all the different username in a table if multiple only display it once

I am trying to display all the usernames in a table however if there is multiple of the same user only display once.我试图在表中显示所有用户名,但是如果有多个相同的用户只显示一次。 It currently works on the first row in the database but doesn't work on the other users in the table它目前适用于数据库中的第一行,但不适用于表中的其他用户

<?php 
$sql = " SELECT * FROM messages WHERE reciever = '".$_SESSION['name']."' LIMIT 1 ";
$mes = $pdo->query($sql);

while($mess = $mes->fetch())
{
?>         
<li><?php echo " ".$mess['sender']." <a href='my-messages.php?sender=".$mess['sender'] ."' > View</a> " ?></li>                   

<?php } ?>

您想使用Select DISTINCT

SELECT DISTINCT SENDER FROM messages WHERE reciever = '".$_SESSION['name']."'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM