How to convert users id to username

SBste01

Member
Dec 16, 2013
44
3
Hey,
I've noticed that on a lot of retros, the Hot Rooms on the /community page has the owners username on it. When I put it into my community page, it comes up with the user's ID instead of the username. Is there a way you are able to convert it from their ID to their username? Attached below is a photo of it and the /community.php page.

Photo:
You must be registered for see images attach

community.php
<?php
$eo = 'even';

function GenerateRoomOccupancy($usersNow, $usersMax)
{
$num = 1;
$percentage = intval(($usersNow / $usersMax) * 100);

if ($percentage <= 0)
{
$num = 1;
}
else if ($percentage < 35)
{
$num = 2;
}
else if ($percentage < 75)
{
$num = 3;
}
else if ($percentage < 100)
{
$num = 4;
}
else if ($percentage >= 100)
{
$num = 5;
}

return 'room-occupancy-' . $num;
}

?>
<div class="habblet-container ">
<div class="cbb clearfix settings ">

<h2 class="title">Hot Rooms</h2>

<style type="text/css">
.room-occupancy-1 { background-image: url('{url}/app/tpl/skins/Habbo/images/rooms/room_icon_1.gif') !important; }
.room-occupancy-2 { background-image: url('{url}/app/tpl/skins/Habbo/images/rooms/room_icon_2.gif') !important; }
.room-occupancy-3 { background-image: url('{url}/app/tpl/skins/Habbo/images/rooms/room_icon_3.gif') !important; }
.room-occupancy-4 { background-image: url('{url}/app/tpl/skins/Habbo/images/rooms/room_icon_4.gif') !important; }
.room-occupancy-5 { background-image: url('{url}/app/tpl/skins/Habbo/images/rooms/room_icon_5.gif') !important; }
</style>

<div id="rooms-habblet-list-container-h124" class="recommendedrooms-lite-habblet-list-container">
<ul class="habblet-list">

<?php

$get = mysql_query("SELECT * FROM rooms WHERE roomtype = 'private' ORDER BY users_now DESC LIMIT 5")or die(mysql_error());

while ($room = mysql_fetch_assoc($get))
{
if ($eo == 'even')
{
$eo = 'odd';
}
else
{
$eo = 'even';
}

echo '<li class="' . $eo . '">
<span class="clearfix enter-room-link ' . GenerateRoomOccupancy($room['users_now'], $room['users_max']) . '" title="Go There" roomid="' . $room['id'] . '">
<span class="room-enter">Enter room</span>
<span class="room-name">' . ($room['caption']) . '</span>
<span class="room-description">' . ($room['description']) . '</span>
<span class="room-owner">Owner: <a href="/home/' . ($room['owner']) . '">' . ($room['owner']) . '</a></span>
</span>
</li>';
}

?>

<div id="room-more-data-h124" style="display: none">
<ul class="habblet-list room-more-data">

<?php

$get = mysql_query("SELECT * FROM rooms WHERE roomtype = 'private' ORDER BY users_now DESC LIMIT 6,10")or die(mysql_error());

while ($room = mysql_fetch_assoc($get))
{
if ($eo == 'even')
{
$eo = 'odd';
}
else
{
$eo = 'even';
}

echo '<li class="' . $eo . '">
<span class="clearfix enter-room-link ' . GenerateRoomOccupancy($room['users_now'], $room['users_max']) . '" title="Go There" roomid="' . $room['id'] . '">
<span class="room-enter">Enter room</span> <br>
<span class="room-name">' . ($room['caption']) . '</span> <br>
<span class="room-description">' . ($room['description']) . '</span>
<span class="room-owner">Owner: <a href="/home/' . ($room['owner']) . '">' . ($room['owner']) . '</a></span>
</span>
</li>';
}

?>

</ul>
</div>

<div class="clearfix">
<a href="#" class="room-toggle-more-data" id="room-toggle-more-data-h124">More Rooms!</a>
</div>

</div>

<script type="text/javascript">
L10N.put("show.more", "Show more rooms");
L10N.put("show.less", "Show less rooms");
var roomListHabblet_h124 = new RoomListHabblet("rooms-habblet-list-container-h124", "room-toggle-more-data-h124", "room-more-data-h124");
</script>

</div>
</div>

I'd really appreciate if you were able to help.
Contact me on our hotel Discord here: or comment below.
 

JayC

Well-Known Member
Aug 8, 2013
5,505
1,401
Try This
<?php
$eo = 'even';

function GenerateRoomOccupancy($usersNow, $usersMax)
{
$num = 1;
$percentage = intval(($usersNow / $usersMax) * 100);

if ($percentage <= 0)
{
$num = 1;
}
else if ($percentage < 35)
{
$num = 2;
}
else if ($percentage < 75)
{
$num = 3;
}
else if ($percentage < 100)
{
$num = 4;
}
else if ($percentage >= 100)
{
$num = 5;
}

return 'room-occupancy-' . $num;
}

function userIdToUsername($userId){
$getUserName = mysql_query("SELECT `username` FROM `user` WHERE `id` = '".$userId."' LIMIT 1");

if(mysql_num_rows($getUserName) == 1){
$usersName = mysql_fetch_assoc($getUserName);
return $usersName['username'];
}else{
return $userId;
}

}
?>
<div class="habblet-container ">
<div class="cbb clearfix settings ">

<h2 class="title">Hot Rooms</h2>

<style type="text/css">
.room-occupancy-1 { background-image: url('{url}/app/tpl/skins/Habbo/images/rooms/room_icon_1.gif') !important; }
.room-occupancy-2 { background-image: url('{url}/app/tpl/skins/Habbo/images/rooms/room_icon_2.gif') !important; }
.room-occupancy-3 { background-image: url('{url}/app/tpl/skins/Habbo/images/rooms/room_icon_3.gif') !important; }
.room-occupancy-4 { background-image: url('{url}/app/tpl/skins/Habbo/images/rooms/room_icon_4.gif') !important; }
.room-occupancy-5 { background-image: url('{url}/app/tpl/skins/Habbo/images/rooms/room_icon_5.gif') !important; }
</style>

<div id="rooms-habblet-list-container-h124" class="recommendedrooms-lite-habblet-list-container">
<ul class="habblet-list">

<?php

$get = mysql_query("SELECT * FROM rooms WHERE roomtype = 'private' ORDER BY users_now DESC LIMIT 5")or die(mysql_error());

while ($room = mysql_fetch_assoc($get))
{
if ($eo == 'even')
{
$eo = 'odd';
}
else
{
$eo = 'even';
}

echo '<li class="' . $eo . '">
<span class="clearfix enter-room-link ' . GenerateRoomOccupancy($room['users_now'], $room['users_max']) . '" title="Go There" roomid="' . $room['id'] . '">
<span class="room-enter">Enter room</span>
<span class="room-name">' . ($room['caption']) . '</span>
<span class="room-description">' . ($room['description']) . '</span>
<span class="room-owner">Owner: <a href="/home/' . ($room['owner']) . '">' . ($room['owner']) . '</a></span>
</span>
</li>';
}

?>

<div id="room-more-data-h124" style="display: none">
<ul class="habblet-list room-more-data">

<?php

$get = mysql_query("SELECT * FROM rooms WHERE roomtype = 'private' ORDER BY users_now DESC LIMIT 6,10")or die(mysql_error());

while ($room = mysql_fetch_assoc($get))
{
if ($eo == 'even')
{
$eo = 'odd';
}
else
{
$eo = 'even';
}

echo '<li class="' . $eo . '">
<span class="clearfix enter-room-link ' . GenerateRoomOccupancy($room['users_now'], $room['users_max']) . '" title="Go There" roomid="' . $room['id'] . '">
<span class="room-enter">Enter room</span> <br>
<span class="room-name">' . ($room['caption']) . '</span> <br>
<span class="room-description">' . ($room['description']) . '</span>
<span class="room-owner">Owner: <a href="/home/' . ($room['owner']) . '">' . userIdToUsername($room['owner']) . '</a></span>
</span>
</li>';
}

?>

</ul>
</div>

<div class="clearfix">
<a href="#" class="room-toggle-more-data" id="room-toggle-more-data-h124">More Rooms!</a>
</div>

</div>

<script type="text/javascript">
L10N.put("show.more", "Show more rooms");
L10N.put("show.less", "Show less rooms");
var roomListHabblet_h124 = new RoomListHabblet("rooms-habblet-list-container-h124", "room-toggle-more-data-h124", "room-more-data-h124");
</script>

</div>
</div>
 

SBste01

Member
Dec 16, 2013
44
3
Try This
<?php
$eo = 'even';

function GenerateRoomOccupancy($usersNow, $usersMax)
{
$num = 1;
$percentage = intval(($usersNow / $usersMax) * 100);

if ($percentage <= 0)
{
$num = 1;
}
else if ($percentage < 35)
{
$num = 2;
}
else if ($percentage < 75)
{
$num = 3;
}
else if ($percentage < 100)
{
$num = 4;
}
else if ($percentage >= 100)
{
$num = 5;
}

return 'room-occupancy-' . $num;
}

function userIdToUsername($userId){
$getUserName = mysql_query("SELECT `username` FROM `user` WHERE `id` = '".$userId."' LIMIT 1");

if(mysql_num_rows($getUserName) == 1){
$usersName = mysql_fetch_assoc($getUserName);
return $usersName['username'];
}else{
return $userId;
}

}
?>
<div class="habblet-container ">
<div class="cbb clearfix settings ">

<h2 class="title">Hot Rooms</h2>

<style type="text/css">
.room-occupancy-1 { background-image: url('{url}/app/tpl/skins/Habbo/images/rooms/room_icon_1.gif') !important; }
.room-occupancy-2 { background-image: url('{url}/app/tpl/skins/Habbo/images/rooms/room_icon_2.gif') !important; }
.room-occupancy-3 { background-image: url('{url}/app/tpl/skins/Habbo/images/rooms/room_icon_3.gif') !important; }
.room-occupancy-4 { background-image: url('{url}/app/tpl/skins/Habbo/images/rooms/room_icon_4.gif') !important; }
.room-occupancy-5 { background-image: url('{url}/app/tpl/skins/Habbo/images/rooms/room_icon_5.gif') !important; }
</style>

<div id="rooms-habblet-list-container-h124" class="recommendedrooms-lite-habblet-list-container">
<ul class="habblet-list">

<?php

$get = mysql_query("SELECT * FROM rooms WHERE roomtype = 'private' ORDER BY users_now DESC LIMIT 5")or die(mysql_error());

while ($room = mysql_fetch_assoc($get))
{
if ($eo == 'even')
{
$eo = 'odd';
}
else
{
$eo = 'even';
}

echo '<li class="' . $eo . '">
<span class="clearfix enter-room-link ' . GenerateRoomOccupancy($room['users_now'], $room['users_max']) . '" title="Go There" roomid="' . $room['id'] . '">
<span class="room-enter">Enter room</span>
<span class="room-name">' . ($room['caption']) . '</span>
<span class="room-description">' . ($room['description']) . '</span>
<span class="room-owner">Owner: <a href="/home/' . ($room['owner']) . '">' . ($room['owner']) . '</a></span>
</span>
</li>';
}

?>

<div id="room-more-data-h124" style="display: none">
<ul class="habblet-list room-more-data">

<?php

$get = mysql_query("SELECT * FROM rooms WHERE roomtype = 'private' ORDER BY users_now DESC LIMIT 6,10")or die(mysql_error());

while ($room = mysql_fetch_assoc($get))
{
if ($eo == 'even')
{
$eo = 'odd';
}
else
{
$eo = 'even';
}

echo '<li class="' . $eo . '">
<span class="clearfix enter-room-link ' . GenerateRoomOccupancy($room['users_now'], $room['users_max']) . '" title="Go There" roomid="' . $room['id'] . '">
<span class="room-enter">Enter room</span> <br>
<span class="room-name">' . ($room['caption']) . '</span> <br>
<span class="room-description">' . ($room['description']) . '</span>
<span class="room-owner">Owner: <a href="/home/' . ($room['owner']) . '">' . userIdToUsername($room['owner']) . '</a></span>
</span>
</li>';
}

?>

</ul>
</div>

<div class="clearfix">
<a href="#" class="room-toggle-more-data" id="room-toggle-more-data-h124">More Rooms!</a>
</div>

</div>

<script type="text/javascript">
L10N.put("show.more", "Show more rooms");
L10N.put("show.less", "Show less rooms");
var roomListHabblet_h124 = new RoomListHabblet("rooms-habblet-list-container-h124", "room-toggle-more-data-h124", "room-more-data-h124");
</script>

</div>
</div>
Still doesn't seem to work D:
 

Jerry

not rly active lol
Jul 8, 2013
1,957
522
Try This
<?php
$eo = 'even';

function GenerateRoomOccupancy($usersNow, $usersMax)
{
$num = 1;
$percentage = intval(($usersNow / $usersMax) * 100);

if ($percentage <= 0)
{
$num = 1;
}
else if ($percentage < 35)
{
$num = 2;
}
else if ($percentage < 75)
{
$num = 3;
}
else if ($percentage < 100)
{
$num = 4;
}
else if ($percentage >= 100)
{
$num = 5;
}

return 'room-occupancy-' . $num;
}

function userIdToUsername($userId){
$getUserName = mysql_query("SELECT `username` FROM `user` WHERE `id` = '".$userId."' LIMIT 1");

if(mysql_num_rows($getUserName) == 1){
$usersName = mysql_fetch_assoc($getUserName);
return $usersName['username'];
}else{
return $userId;
}

}
?>
<div class="habblet-container ">
<div class="cbb clearfix settings ">

<h2 class="title">Hot Rooms</h2>

<style type="text/css">
.room-occupancy-1 { background-image: url('{url}/app/tpl/skins/Habbo/images/rooms/room_icon_1.gif') !important; }
.room-occupancy-2 { background-image: url('{url}/app/tpl/skins/Habbo/images/rooms/room_icon_2.gif') !important; }
.room-occupancy-3 { background-image: url('{url}/app/tpl/skins/Habbo/images/rooms/room_icon_3.gif') !important; }
.room-occupancy-4 { background-image: url('{url}/app/tpl/skins/Habbo/images/rooms/room_icon_4.gif') !important; }
.room-occupancy-5 { background-image: url('{url}/app/tpl/skins/Habbo/images/rooms/room_icon_5.gif') !important; }
</style>

<div id="rooms-habblet-list-container-h124" class="recommendedrooms-lite-habblet-list-container">
<ul class="habblet-list">

<?php

$get = mysql_query("SELECT * FROM rooms WHERE roomtype = 'private' ORDER BY users_now DESC LIMIT 5")or die(mysql_error());

while ($room = mysql_fetch_assoc($get))
{
if ($eo == 'even')
{
$eo = 'odd';
}
else
{
$eo = 'even';
}

echo '<li class="' . $eo . '">
<span class="clearfix enter-room-link ' . GenerateRoomOccupancy($room['users_now'], $room['users_max']) . '" title="Go There" roomid="' . $room['id'] . '">
<span class="room-enter">Enter room</span>
<span class="room-name">' . ($room['caption']) . '</span>
<span class="room-description">' . ($room['description']) . '</span>
<span class="room-owner">Owner: <a href="/home/' . ($room['owner']) . '">' . ($room['owner']) . '</a></span>
</span>
</li>';
}

?>

<div id="room-more-data-h124" style="display: none">
<ul class="habblet-list room-more-data">

<?php

$get = mysql_query("SELECT * FROM rooms WHERE roomtype = 'private' ORDER BY users_now DESC LIMIT 6,10")or die(mysql_error());

while ($room = mysql_fetch_assoc($get))
{
if ($eo == 'even')
{
$eo = 'odd';
}
else
{
$eo = 'even';
}

echo '<li class="' . $eo . '">
<span class="clearfix enter-room-link ' . GenerateRoomOccupancy($room['users_now'], $room['users_max']) . '" title="Go There" roomid="' . $room['id'] . '">
<span class="room-enter">Enter room</span> <br>
<span class="room-name">' . ($room['caption']) . '</span> <br>
<span class="room-description">' . ($room['description']) . '</span>
<span class="room-owner">Owner: <a href="/home/' . ($room['owner']) . '">' . userIdToUsername($room['owner']) . '</a></span>
</span>
</li>';
}

?>

</ul>
</div>

<div class="clearfix">
<a href="#" class="room-toggle-more-data" id="room-toggle-more-data-h124">More Rooms!</a>
</div>

</div>

<script type="text/javascript">
L10N.put("show.more", "Show more rooms");
L10N.put("show.less", "Show less rooms");
var roomListHabblet_h124 = new RoomListHabblet("rooms-habblet-list-container-h124", "room-toggle-more-data-h124", "room-more-data-h124");
</script>

</div>
</div>

You forgot to change:
Owner: <a href="/home/' . ($room['owner']) . '">' . ($room['owner']) . '</a></span>
as well, there's two of them and you only changed it for one of them.

Find the quoted code above and change that to:
Owner: <a href="/home/' . ($room['owner']) . '">' . userIdToUsername($room['owner']) . '</a></span>
 

Users who are viewing this thread

Top