get rank title

Need some coding help with a MOD or tweak you are working on? - Ask here.
Forum rules
Ask for support specifically regarding coding help with phpBB3.
Not for generic usability questions or support.

get rank title

Postby jwxie » 21 Mar 2009, 13:09

I tried to get the rank title using get method, and user->data method
but when i look into the code more carefully, i didn't get the right row, it only generated the number rank, like 1, 2, 3, 4

i am trying to pull it out and display it on the index
anyone can help me out?
jwxie
Cadet III
Cadet III
 
Posts: 38
Joined: 04 Apr 2007, 12:12
Gender: Male


Re: get rank title

Postby Erik Frèrejean » 21 Mar 2009, 13:35

The value that is stored in the $user->data['user_rank'] variable is the id of the rank. You can use this to fetch the actual rank from the RANKS_TABLE
Code: Select all
$sql 'SELECT *
   FROM ' 
RANKS_TABLE '
   WHERE rank_id = ' 
$user->data['user_rank']; 
Image Proud member of the phpBB support team
Image STG Support team member | Image STG Moderator team member
Image
User avatar
Erik Frèrejean    
phpBB Team Member
phpBB Team Member
 
Posts: 1021
Joined: 03 Dec 2007, 00:49
Location: USERS_TABLE
Favorite Team: phpBB teams
Gender: Male
phpBB Knowledge: 9

Re: get rank title

Postby jwxie » 21 Mar 2009, 16:46

hey thanks. this is my code now
is it good to you guys?
i can display it, just asking :]

Code: Select all
$sql = 'SELECT rank_title
   FROM ' . RANKS_TABLE . '
   WHERE rank_id = ' . $user->data['user_rank'];
$result = $db->sql_query($sql);
$rank_title = $db->sql_fetchfield('rank_title');
$db->sql_freeresult($result);
jwxie
Cadet III
Cadet III
 
Posts: 38
Joined: 04 Apr 2007, 12:12
Gender: Male

Re: get rank title

Postby Erik Frèrejean » 21 Mar 2009, 17:46

Well if you can print $rank_title and it displays whatever you expect it to display you can assume its correct ;).
Image Proud member of the phpBB support team
Image STG Support team member | Image STG Moderator team member
Image
User avatar
Erik Frèrejean    
phpBB Team Member
phpBB Team Member
 
Posts: 1021
Joined: 03 Dec 2007, 00:49
Location: USERS_TABLE
Favorite Team: phpBB teams
Gender: Male
phpBB Knowledge: 9

Re: get rank title

Postby jwxie » 21 Mar 2009, 17:56

Code: Select all
$result = $db->sql_query($sql);
$db->sql_freeresult($result);

just a minor question
sometime i don't see sql_freeresult in other parts of the phpbb files
jwxie
Cadet III
Cadet III
 
Posts: 38
Joined: 04 Apr 2007, 12:12
Gender: Male

Re: get rank title

Postby Erik Frèrejean » 21 Mar 2009, 18:05

The $db->sql_freeresult($result); is used always. I think that you are tricked by the fact that it isn't always called right after the query, sometimes this isn't possible as you might want to re-use the result later on or just don't want to worry about it.
Due to the way phpBB is setup you can (but shouldn't) leave the call out at all as long you call the garbage_collection() function somewhere (this is done in page_footer()) as this function calls the $db->sql_close() method. This method will run $db->sql_freeresult($result) on all open queries before it closes the database connection.
Good coding practices however makes you to call it yourself.
Image Proud member of the phpBB support team
Image STG Support team member | Image STG Moderator team member
Image
User avatar
Erik Frèrejean    
phpBB Team Member
phpBB Team Member
 
Posts: 1021
Joined: 03 Dec 2007, 00:49
Location: USERS_TABLE
Favorite Team: phpBB teams
Gender: Male
phpBB Knowledge: 9

Re: get rank title

Postby jwxie » 21 Mar 2009, 18:44

Erik Frèrejean wrote:The $db->sql_freeresult($result); is used always. I think that you are tricked by the fact that it isn't always called right after the query, sometimes this isn't possible as you might want to re-use the result later on or just don't want to worry about it.
Due to the way phpBB is setup you can (but shouldn't) leave the call out at all as long you call the garbage_collection() function somewhere (this is done in page_footer()) as this function calls the $db->sql_close() method. This method will run $db->sql_freeresult($result) on all open queries before it closes the database connection.
Good coding practices however makes you to call it yourself.

Erik, thanks a lot
now i understood.
yes i was reading phpbb files,. and i didn't notice that in fact
i was tricked by it, thanks again bro
jwxie
Cadet III
Cadet III
 
Posts: 38
Joined: 04 Apr 2007, 12:12
Gender: Male


Return to phpBB3 Coding Assistance

Who is online

Users browsing this forum: ccBot [Bot] and 7 guests