Show rank name instead of rank id

Proximity

IDK?
Feb 13, 2014
673
56
How can i display a rank name instead of the id of the rank

Like SELECT rank FROM users

SELECT name from ranks where id

or something like that?
 

RastaLulz

fight teh power
Staff member
May 3, 2010
3,934
3,933
You'd want to use an INNER JOIN.

Something like this should do the trick:
Code:
SELECT users.name, ranks.name
FROM users
INNER JOIN ranks
ON ranks.id = users.rank
 

Proximity

IDK?
Feb 13, 2014
673
56
So like

$rankg = mysql_fetch_array(mysql_query("SELECT '.$_SESSION['user']['id'].', ranks.name FROM users INNER JOIN ranks ON ranks.id = users.rank"));
 

BIOS

ಠ‿ಠ
Apr 25, 2012
906
247
Add another column "title" to the ranks table, give each rank a title
Code:
SELECT r.title FROM ranks r LEFT JOIN users u on u.rank = r.id WHERE u.id = $_SESSION['user']['id']
 

Proximity

IDK?
Feb 13, 2014
673
56
<div><img src="%www%/images/terms_icon.gif"> Rank: <b><?php echo $rankg; ?></b></div>
And
$rankg = mysql_fetch_array(mysql_query("SELECT r.title FROM ranks r LEFT JOIN users u on u.rank = r.id WHERE u.id = '".$_SESSION['user']['id']."'"));
it isn't working
 
It shows array
 

BIOS

ಠ‿ಠ
Apr 25, 2012
906
247
<div><img src="%www%/images/terms_icon.gif"> Rank: <b><?php echo $rankg; ?></b></div>
And
$rankg = mysql_fetch_array(mysql_query("SELECT r.title FROM ranks r LEFT JOIN users u on u.rank = r.id WHERE u.id = '".$_SESSION['user']['id']."'"));
it isn't working
 
It shows array
Did you add the new column?

Also run the query in a SQL admin tool e.g. Navicat to see what result you get.

SELECT r.title FROM ranks r LEFT JOIN users u on u.rank = r.id WHERE u.id = '1';
 

Proximity

IDK?
Feb 13, 2014
673
56
<div><img src="%www%/images/terms_icon.gif"> Rank: <b><?php echo $rankg; ?></b></div>
and
Code:
$rankg = mysql_fetch_array(mysql_query("SELECT r.title FROM ranks r LEFT JOIN users u on u.rank = r.id WHERE u.id = '".$_SESSION['user']['id']."'"));
$getstats = mysql_fetch_assoc(mysql_query("SELECT * FROM user_stats WHERE id = '".$_SESSION['user']['id']."'"));
$getLook = mysql_fetch_assoc(mysql_query("SELECT * FROM users WHERE id = '".$_SESSION['user']['id']."'"));
?>

that is the code
 

Brad

Well-Known Member
Jun 5, 2012
2,320
993
I think this is what you're asking for?
Code:
$userinfo = mysql_query("SELECT id,username,rank FROM users WHERE username='" . $_SESSION['user']['username'] . "'");
$get2 = mysql_fetch_assoc($userinfo);

$getrank= mysql_query("SELECT id,rank FROM ranks WHERE id= "'.$get2['rank'].'");
$getr2 = mysql_fetch_assoc($getrank);
Then put
<?php echo $getr2['id']; ?> Where ever you want it to display?
 
Last edited:

Proximity

IDK?
Feb 13, 2014
673
56
It had * because of the other things..

Code:
             <div><img src="%www%/images/icon_habbo_small.png"> User ID: <b><?php echo $getLook['id']; ?></b></div> 
               <div><img src="%www%/images/credits.png"> Credits: <b><?php echo $getLook['credits']; ?></b></div> 
               <div><img src="%www%/images/duckets.png"> Duckets: <b><?php echo $getLook['activity_points']; ?></b></div> 
               <div><img src="%www%/images/diamond.png"> Diamonds: <b><?php echo $getLook['seasonal_currency']; ?></b></div> 
               <div><img src="%www%/images/owner_icon.gif"> ROTW Points: <b><?php echo $getLook['ROTW_Points']; ?></b></div> 
               <div><img src="%www%/images/terms_icon.gif"> Rank: <b><?php echo $rankg; ?></b></div>
 

Users who are viewing this thread

Top