我有一个私人消息系统,我有这个函数可以返回对话中所有用户的 ID(发件人除外):
function findOtherUsersInConversation($conversation_id) {
$sender = findMessageSenderId($conversation_id);
$query = mysql_query("SELECT user_id FROM message_partecipant WHERE conversation_id = '$conversation_id' AND user_id !=$sender");
while ($row = mysql_fetch_array($query)) {
$user_id = $row['user_id'];
print_r($user_id);
}
}
print_r 像这样返回 ID(例如 id100 和 id 101):
100101//which is not what i'm trying to do
我有另一个函数可以在数据库中查找用户名,因此对于每个用户 ID,我想以这种格式获取他们的用户名:
echo usernameFromId($user_id)// this should echo out all the username like this (user a, user b, user c)
我想我必须做一个 foreach 循环,但我想不出怎么做。