I have a private message system and I have this function that returns the IDs of all the users in the conversation (except the sender):
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 return the Ids (for instance id100 and id 101)like this:
100101//which is not what i'm trying to do
I have another function that find the username in the database so for each user id I would like to get their usernames in this format:
echo usernameFromId($user_id)// this should echo out all the username like this (user a, user b, user c)
I think I have to do a foreach loop but I can't think how.
SELECT user_idin the fields you want.mysql_*functions in new code. They were removed from PHP 7.0.0 in 2015. Instead, use prepared statements via PDO or MySQLi. See Why shouldn't I use mysql_* functions in PHP? for more information.