私はプライベートメッセージシステムを持っており、会話のすべてのユーザー(送信者を除く)の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ループを実行する必要があると思いますが、その方法は考えられません。