Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> v2.4 RN Issues
Author Message
dezblack
Hangin' Around



Joined: Nov 26, 2008
Posts: 38

PostPosted: Mon Mar 29, 2010 7:51 pm Reply with quote

I have looked for documentation on how to display the custom fields for users on the forums. Under their posts, it now has username, avatar, rank, joined date and location. I would like some or all of my custom field values from RNYA to show as well. How do I do this?
 
View user's profile Send private message
Palbin
Site Admin



Joined: Mar 30, 2006
Posts: 2583
Location: Pittsburgh, Pennsylvania

PostPosted: Mon Mar 29, 2010 9:51 pm Reply with quote

Do you have any PHP skills? If so I can give you a quick idea how to do it, but if not I don't have the time to do it for you. I know something like this has been talked about before, but I have no idea where you would find it in these forums.

_________________
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan. 
View user's profile Send private message
dezblack







PostPosted: Tue Mar 30, 2010 1:27 am Reply with quote

Ok, I was wondering if there was something built in I was missing, guess not Wink.

I do have a little php skill. I found the tables I'm looking for in nuke_users_field_values.

I found this in viewtopic.php:

Code:
/ Go ahead and pull all data for this topic

//
$sql = "SELECT  u.username, u.user_id, u.user_posts, u.user_from, u.user_website, u.user_email, u.user_icq, u.user_aim, u.user_yim, u.user_regdate, u.user_msnm, u.user_viewemail, u.user_rank, u.user_sig, u.user_sig_bbcode_uid, u.user_avatar, u.user_avatar_type, u.user_allowavatar, u.user_allowsmile, p.*,  pt.post_text, pt.post_subject, pt.bbcode_uid
        FROM " . POSTS_TABLE . " p, " . USERS_TABLE . " u, " . POSTS_TEXT_TABLE . " pt
        WHERE p.topic_id = '$topic_id'
                $limit_posts_time
                AND pt.post_id = p.post_id
                AND u.user_id = p.poster_id
            
        ORDER BY p.post_time $post_time_order
        LIMIT $start, ".$board_config['posts_per_page'];
if ( !($result = $db->sql_query($sql)) )
{
        message_die(GENERAL_ERROR, "Could not obtain post/user information.", '', __LINE__, __FILE__, $sql);
}

$postrow = array();
if ($row = $db->sql_fetchrow($result))
{


and this too(seems to have some info already being shown):

Code:
// Again this will be handled by the templating

        // code at some point
        //
        $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
        $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];

        $template->assign_block_vars('postrow', array(
                'ROW_COLOR' => '#' . $row_color,
                'ROW_CLASS' => $row_class,
                'POSTER_NAME' => $poster,
                'POSTER_RANK' => $poster_rank,
                'RANK_IMAGE' => $rank_image,
                'POSTER_JOINED' => $poster_joined,
                'POSTER_POSTS' => $poster_posts,
                'POSTER_FROM' => $poster_from,
                'POSTER_AVATAR' => $poster_avatar,
                'POST_DATE' => $post_date,
                'POST_SUBJECT' => $post_subject,
                'MESSAGE' => $message,
                'SIGNATURE' => $user_sig,
                'EDITED_MESSAGE' => $l_edited_by,
            


Can I adjust the top code to include a query matching uid from the nuke_users_field_values to the u.user_id:
Code:
/ Go ahead and pull all data for this topic

//
$sql = "SELECT  c.*, u.username, u.user_id, u.user_posts, u.user_from, u.user_website, u.user_email, u.user_icq, u.user_aim, u.user_yim, u.user_regdate, u.user_msnm, u.user_viewemail, u.user_rank, u.user_sig, u.user_sig_bbcode_uid, u.user_avatar, u.user_avatar_type, u.user_allowavatar, u.user_allowsmile, p.*,  pt.post_text, pt.post_subject, pt.bbcode_uid
        FROM " . WHATGOESHERE?? . " c, " . POSTS_TABLE . " p, " . USERS_TABLE . " u, " . POSTS_TEXT_TABLE . " pt
        WHERE p.topic_id = '$topic_id'
                $limit_posts_time
                AND pt.post_id = p.post_id
                AND u.user_id = p.poster_id
   AND c.uid=u.user_id         
        ORDER BY p.post_time $post_time_order
        LIMIT $start, ".$board_config['posts_per_page'];
if ( !($result = $db->sql_query($sql)) )
{
        message_die(GENERAL_ERROR, "Could not obtain post/user information.", '', __LINE__, __FILE__, $sql);
}

$postrow = array();
if ($row = $db->sql_fetchrow($result))




and then set the array with something like:
Code:
'1' => $user_level,


And then put the code in the template for
Code:
$user_level

I tried but it did not work, I'm assuming the WHATGOESHERE? I am using is incorrect..
I was using users_field_values

********EDIT**********
I used nuke_users_field_values and it worked.
My problem now is the array. I see each UID has 4 fid with 4 value tables.
How do I pull the info from the correct FID value to post to the array?
 
dezblack







PostPosted: Tue Mar 30, 2010 11:18 am Reply with quote

am i on the right path or should I do something differently?
 
Palbin







PostPosted: Thu Apr 01, 2010 6:47 pm Reply with quote

Yes, you are on the right path. I haven't had time to look into exactly how this would be done.
 
Palbin







PostPosted: Thu Apr 01, 2010 9:37 pm Reply with quote

In /modules/Forums/viewtopic.php find lines 414-425:
Code:


$postrow = array();
if ($row = $db->sql_fetchrow($result))
{
        do
        {
                $postrow[] = $row;
        }
        while ($row = $db->sql_fetchrow($result));
        $db->sql_freeresult($result);

        $total_posts = count($postrow);
}

Change to:
Code:


$postrow = array();
$userids= array();
if ($postrow = $db->sql_fetchrowset($result)) {
   foreach($postrow as $key => $value) {
      $sql  = 'SELECT ufv.value as value,  uf.name as name
            FROM `' . $user_prefix . '_users_field_values` ufv, `' . $user_prefix . '_users_fields` uf
            WHERE ufv.uid="' . $postrow[$key]['user_id'] . '"
                  AND uf.fid = ufv.fid';
      $results = $db->sql_query($sql);
      $row = $db->sql_fetchrowset($results, MYSQL_ASSOC);
      foreach($row as $key2 => $value2) {
         $postrow[$key]['custom_fields'][$row[$key2]['name']] = $row[$key2]['value'];
      }
   }
   $db->sql_freeresult($result);
   $total_posts = count($postrow);
}


Then around lines 1195 find:
Code:


        $template->assign_block_vars('postrow', array(
                'ROW_COLOR' => '#' . $row_color,
                'ROW_CLASS' => $row_class,
                'POSTER_NAME' => $poster,
                'POSTER_RANK' => $poster_rank,
                'RANK_IMAGE' => $rank_image,
                'POSTER_JOINED' => $poster_joined,
                'POSTER_POSTS' => $poster_posts,
                'POSTER_FROM' => $poster_from,
                'POSTER_AVATAR' => $poster_avatar,
                'POST_DATE' => $post_date,
                'POST_SUBJECT' => $post_subject,
                'MESSAGE' => $message,
                'SIGNATURE' => $user_sig,
                'EDITED_MESSAGE' => $l_edited_by,

After add the follwoing with "color" being the name of the custom field you want to use:
Code:


'COLOR' =>$postrow[$i]['custom_fields']['color'],


Then open /themes/YOUR_THEME/forums/viewtopic_body.tpl. If you theme does not have forum templates open /modules/Forums/templates/viewtopic_body.tpl. Again using "color" as an example all you need to do is add the following in the template to use the field vlaue:
Code:


{postrow.COLOR}


For example if you wanted to display the users color under the their number of posts you would would find this around line 33:
Code:


{postrow.POSTER_POSTS}<br />
{postrow.POSTER_FROM}</span><br />

Change to:
Code:


{postrow.POSTER_POSTS}<br />
{postrow.COLOR}<br />
{postrow.POSTER_FROM}</span><br />
 
dezblack







PostPosted: Sat Apr 03, 2010 6:07 pm Reply with quote

thank you! this helps alot. I appreciate your time for posting this
 
dezblack







PostPosted: Mon Apr 12, 2010 2:59 pm Reply with quote

I have decided to pull the needed info from a different table. I have it working great per adjusting your instructions with:

Code:


//Guild Rank//

$sql = "SELECT name, rank FROM lotroster WHERE name='$poster'";

if ( !($result = $db->sql_query($sql)) )
{
   message_die(GENERAL_ERROR, 'Could not obtain Roster information', '', __LINE__, __FILE__, $sql);
}

$lotroster = array();

while ( $row = $db->sql_fetchrow($result) )


$lotroster_rank = $row['rank'];


$db->sql_freeresult($result);


I then send it to the template as you said. My problem is that I have members on the forum that are not in the database I am querying. So for instance, I have a user named Darana. She is not in it, so her result returned is the same as the person above her like this:


Darana
Kell member
Diogo officer
Darana officer
Timmy member
Darana member


Is there a way to make the returned value for her be "Guest", or even Blank?
 
Palbin







PostPosted: Mon Apr 12, 2010 3:57 pm Reply with quote

I can see how you would have the problem you are having. Where exactly are you putting this code you just posted?

I don't have time to look at this right now, but I will.
 
dezblack







PostPosted: Mon Apr 12, 2010 4:47 pm Reply with quote

starting at line 926

right above:

//
// Generate ranks, set them to empty string initially.
//
 
Palbin







PostPosted: Mon Apr 12, 2010 5:25 pm Reply with quote

I need to know the field names in the "lotroster" table. Also do you still need to query the custom fields. I plan on leaving it, but just incase.
 
dezblack







PostPosted: Mon Apr 12, 2010 8:52 pm Reply with quote

no, those fields are now auto-propegated into the lotroster fields by another means. I run a Lotro kin website, lotroster is a script that pulls information for Turbine's database using a key, then displays the information.

Lotroster is a table in the same db as nuke_.
It has fields:
name (this one will always match exactly to nuke_users.username, unless one or the other or both are missing an entry, thats why I use name ='$poster')

char_id
Monster
Rank
Level
Class
Race
Vocation
Origin
Profession1
Proficiency1
Mastery1
Profession2
Proficiency2
Mastery2
Profession3
Proficiency3
Mastery3
PVMPRating
PVMPRank
PVMPPoints
Morale
Power
Armour
Might
Agility
Vitality
Will
Fate
Radiance
MeleeCrit
RangedCrit
TacticalCrit
FearResistance
WoundResistance
DiseaseResistance
PoisonResistance
CommonDef
FireDef
FrostDef
ShadowDef
LightningDef
AcidDef
Block
Evade
Parry

I do not need to pull all of them. I currently use this code to pull the ones I want(level, class, rank, vocation,radiance), but I know there's a better way to do it!

Code:


/////////////////////////////////////
//        lotroster query          //
/////////////////////////////////////



//Character info//


$sql = "SELECT level, class FROM lotroster WHERE name='$poster'";

if ( !($result = $db->sql_query($sql)) )
{
   message_die(GENERAL_ERROR, 'Could not obtain Roster information', '', __LINE__, __FILE__, $sql);
}



while ( $row = $db->sql_fetchrow($result) )

$lotroster_info =    $row['level']." " . $row['class'];

$db->sql_freeresult($result);


//Vocation//

$sql = "SELECT vocation FROM lotroster WHERE name='$poster'";

if ( !($result = $db->sql_query($sql)) )
{
   message_die(GENERAL_ERROR, 'Could not obtain Roster information', '', __LINE__, __FILE__, $sql);
}


$lotroster = array();
while ( $row = $db->sql_fetchrow($result) )

$lotroster_vocation = $row['vocation'];


$db->sql_freeresult($result);

//Guild Rank//

$sql = "SELECT rank FROM lotroster WHERE name='$poster'";

if ( !($result = $db->sql_query($sql)) )
{
   message_die(GENERAL_ERROR, 'Could not obtain Roster information', '', __LINE__, __FILE__, $sql);
}


$lotroster = array();
while ( $row = $db->sql_fetchrow($result) )

$lotroster_rank = $row['rank'];


$db->sql_freeresult($result);


//Radiance//


$sql = "SELECT radiance FROM lotroster WHERE name='$poster'";

if ( !($result = $db->sql_query($sql)) )
{
   message_die(GENERAL_ERROR, 'Could not obtain Roster information', '', __LINE__, __FILE__, $sql);
}


$lotroster = array();
while ( $row = $db->sql_fetchrow($result) )

$lotroster_radiance = $row['radiance'];


$db->sql_freeresult($result);





/////////////////////////////////////
//    END lotroster query          //
/////////////////////////////////////

//then later on after $template-> I added:

'RADIANCE' => $lotroster_radiance,
'RANK' => $lotroster_rank,
'CHAR_INFO' => $lotroster_info,
'VOCATION' => $lotroster_vocation,
 
Palbin







PostPosted: Mon Apr 12, 2010 9:47 pm Reply with quote

I didn't physically try this, but it should work.


In /modules/Forums/viewtopic.php find lines 414-425:
Code:


$postrow = array();
if ($row = $db->sql_fetchrow($result))
{
        do
        {
                $postrow[] = $row;
        }
        while ($row = $db->sql_fetchrow($result));
        $db->sql_freeresult($result);

        $total_posts = count($postrow);
}

Change to:
Code:


$postrow = array();
if ($postrow = $db->sql_fetchrowset($result)) {
   foreach($postrow as $key => $value) {
      $sql = 'SELECT rank, level, class, vocation, radiance FROM lotroster WHERE name="' . $postrow[$key]['username'] . '"';
      $results = $db->sql_query($sql);
      $row = $db->sql_fetchrowset($results, MYSQL_ASSOC);
      foreach($row as $key2 => $value2) {
         $postrow[$key]['custom_fields'][$key2] = $value2;
      }
   }
   $db->sql_freeresult($result);
   $total_posts = count($postrow);
}



Then you would use it like so:
Code:


'RADIANCE' =>  $postrow[$key]['custom_fields']['radiance'],
'RANK' => $postrow[$key]['custom_fields']['rank'],


If this works you can remove the code you posted above.
 
dezblack







PostPosted: Mon Apr 12, 2010 9:57 pm Reply with quote

Warning: Invalid argument supplied for foreach() in ................\modules\Forums\viewtopic.php on line 420


Code:
foreach($row as $key2 => $value2)


Last edited by dezblack on Mon Apr 12, 2010 11:38 pm; edited 1 time in total 
dezblack







PostPosted: Mon Apr 12, 2010 11:05 pm Reply with quote

is this because one of the fields is returning empty due to darana not being in the table?
 
Palbin







PostPosted: Tue Apr 13, 2010 2:48 pm Reply with quote

dezblack, yes try the following.

Code:


$postrow = array();
if ($postrow = $db->sql_fetchrowset($result)) {
   foreach($postrow as $key => $value) {
      $sql = 'SELECT rank, level, class, vocation, radiance FROM lotroster WHERE name="' . $postrow[$key]['username'] . '"';
      if ($results = $db->sql_query($sql)) {
            $row = $db->sql_fetchrowset($results, MYSQL_ASSOC);
            foreach($row as $key2 => $value2) {
               $postrow[$key]['custom_fields'][$key2] = $value2;
            }
      }
   }
   $db->sql_freeresult($result);
   $total_posts = count($postrow);
}
 
dezblack







PostPosted: Tue Apr 13, 2010 5:42 pm Reply with quote

same error message.
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> v2.4 RN Issues

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©