I have this code to get the user name that a friend has messaged to someone like user to from message. mysql_num_rows
is not working and my user names come up as unknown. Does this have something to do with mysql_num_rows()
?
function getusername($userid) {
$sql = "SELECT username FROM user WHERE `id` = '".$userid."' LIMIT 1";
$result = mysql_query($sql);
// Check if there is someone with this id
if(mysql_num_rows($result)) {
// if yes get his username
$row = mysql_fetch_row($result);
return $row[0];
} else {
// if not, name him Unknown
return "Unknown";
}
}