Change theme: 
Search for :    
Previous Blogs
Transformers Blogs
Misc Blogs
Computer/Tech Logs
Movie Reviews
Popular Blogs
ASCII chart
Comment from Tamera on December 24, 2015
Configuring Speedstream 6520 For Modem Only Mode
Comment from Janet on September 13, 2015
Transformers Reviews: MP-19 Smokescreen
Comment from Silagra on August 1, 2015
Transformers Reviews: MP-21 Masterpiece (Bumble) Bee
Comment from google authorship check on June 26, 2015
Aww...It's a Cat...Meow
Comment from vxt on June 4, 2015

RSS Facebook Twitter Instagram
My Tweets
PHPBB3 Tips: How To Query Custom Profile Fields
This blog includes code on how to add custom profile fields to the side profile as well as how to retrieve custom profile fields from outside of the PHPBB pages if you are integrating PHPBB3 with your site.

Adding Fields Within PHPBB3 Pages

In the administrative control panel, you need to add the custom field. Go to USERS & GROUPS, then click on the Custom profile fields link on the left side bar. Click on the, "Create new field" button. Fill out the form.

If you want to add a gender field to the side profile, for example, go to this folder, styles\{ YOUR TEMPLATE }\template and edit the viewtopic_body.html file. Add the code below in the appropriate area.

GENDER is the name that you gave the field in the adminstrative control panel.

Adding Fields In Custom Pages

If you are integrating your site with PHPBB3 and want to get the custom profile fields outside of the PHPBB3 pages, this is the code you need to use.

# Include this code to use the user class from PHPBB.
define('IN_PHPBB', true);
$phpbb_root_path = {PATH TO YOUR FORUM};
$phpEx = "php";
include($phpbb_root_path . 'common.'.$phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
//These are the ones that handle sessions.

# Get the custom field names

$query = "SELECT * FROM `phpbb_profile_fields`";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)) {
     $rowCustomFields[] = $row;

# Get custom field data
$query = "SELECT * FROM `phpbb_profile_fields_data`
     WHERE `phpbb_profile_fields_data`.user_id=".$user->data[user_id];
$result = mysql_query($query);
$rowCustomFieldsData = mysql_fetch_array($result);

if (is_array($rowCustomFields)) {
     foreach($rowCustomFields AS $k => $v) {
# I only check for one type but there are possibly more field types that
# you should check for. I believe field_type=5 is a select dropdown
          if ($rowCustomFields[$k][field_type] == 5) {
# For field_type=5, get the values for them since they are stored
# only as IDs in the fields_data table
               $query = "SELECT `phpbb_profile_fields_lang`.lang_value FROM `phpbb_profile_fields_lang`
               WHERE `phpbb_profile_fields_lang`.field_id=".$rowCustomFields[$k][field_id]."
               AND (`phpbb_profile_fields_lang`.option_id+1)=".$rowCustomFieldsData['pf_'.$rowCustomFields[$k][field_name]];
               $result = mysql_db_query($query);
               $thisUserProfile[$rowCustomFields[$k][field_name]] = mysql_result($result,0,0);
          } else {
# If it's a text field just assign the value
               $thisUserProfile[$rowCustomFields[$k][field_name]] = $rowCustomFieldsData['pf_'.$rowCustomFields[$k][field_name]];

Post a Comment

Total records: 1
Posted by Seebz on 2010-06-10 09:21:04Post #1 - Post link
thank you for the tip

Copyright © Viet Tran. All Rights Reserved. Powered by Content ManagerTM | Top