Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > vBulletin 3.6 > vBulletin 3.6 Add-ons
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Alpha Sort Custom Profile Field in Member List Details »»
Alpha Sort Custom Profile Field in Member List
Version: 1.00, by jpapadpapa jpapadpapa is offline
Developer Last Online: Oct 2013 Show Printable Version Email this Page

Category: Miscellaneous Hacks - Version: 3.6.8 Rating:
Released: 03-22-2008 Last Update: Never Installs: 0
Re-useable Code Code Changes Translations  
No support by the author.

Note: I came up with this very recently and am currently testing it on my board and running into issues after doing a member search. Please do not use this until I have it figured out. If you can help me figure out what is wrong, I would appreciate it! I am very new at this.

Well, I can't believe I have actually done something worthy of being posted. I have shocked myself. Admittedly, I did have a little help from my husband. (Thanks, Honey!)

Anyway, this is a modification for sorting a custom profile field by the letter/alpha sort at the top of the member list. Some forums, such as mine, are better sorted by another field. My forum is for a local group of people who already know one another. So, it makes more sense for them to see everyone alphabetized by their real names. However, we also wanted to allow everyone to pick their own usernames, rather than require them to use real names.

To do this, you must first use this hack to allow your custom field to be shown (without showing all of your custom fields) in the member list.

Once you have that working, you can move it to the first column by changing this code in the memberlist.php (thanks to Andreas for this part):

First, find this:

PHP Code:
default:
        
$sqlsort 'user.username';
        
$sortfield 'username'

Replace it with this (where "X" is the custom field you want to appear and "lastname" is the name of that field):
PHP Code:
default:
        
$sqlsort 'userfield.[COLOR="Red"]fieldX[/COLOR]';
        
$sortfield '[COLOR="Red"]lastname[/COLOR]' 

Then, find this:

PHP Code:
// set defaults and sensible values

if ($sortfield == '')
{
        
$sortfield 'username';


Replace it with this (where "lastname" is the name of the profile field you are using):

PHP Code:
// set defaults and sensible values

if ($sortfield == '')
{
        
$sortfield '[COLOR="Red"]lastname[/COLOR]';


Now you should have your specific custom field listed on your member list as the first column. Finally, to make it sort by the alpha list at the top, you will need to do the following:

Find this code in the memberlist.php:

PHP Code:
   if ($ltr != '')
    {
        if (
$ltr == '#')
        {
            
$condition "username NOT REGEXP(\"^[a-zA-Z]\")";
        }
        else
        {
            
$ltr chr(intval(ord($ltr)));
            
$condition 'username LIKE("' $db->escape_string_like($ltr) . '%")';
        }
    } 

Replace it with this (again, using your specific custom field number and name instead of "fieldX" and "lastname"):

PHP Code:
if ($ltr != '')
    {
        if (
$ltr == '#')
        {
            if (
$sortfield == '[COLOR="Red"]lastname[/COLOR]')
            {
                
$condition "[COLOR="Red"]fieldX[/COLOR] NOT REGEXP(\"^[a-zA-Z]\")";
            }
            else
            {
                
$condition "username NOT REGEXP(\"^[a-zA-Z]\")";
            }
        }
        else
        {
            
$ltr chr(intval(ord($ltr)));

            if (
$sortfield == [COLOR="Red"]'lastname'[/COLOR]) 
            {
                
$condition '[COLOR="Red"]fieldX[/COLOR] LIKE("' $db->escape_string_like($ltr) . '%")';
            }
            else
            {    
                
$condition 'username LIKE("' $db->escape_string_like($ltr) . '%")';
            }
        }
    } 
That's it! I hope this helps someone else. If there are any problems with it, let me know. It was quite a process for this newbie to figure it all out and it's possible I may have missed a step here.

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.

Comments
  #2  
Old 03-23-2008, 10:06 PM
aproape's Avatar
aproape aproape is offline
 
Join Date: Dec 2007
Posts: 71
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This sounds very useful! Thanks - we'll try it out very soon!

*poof*
aproape
Reply With Quote
  #3  
Old 07-15-2009, 06:37 PM
anthonym16 anthonym16 is offline
 
Join Date: Feb 2009
Posts: 12
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks, this post did help me. I wish there was a way to do this in a plug-in... There just aren't enough hooks to do it though.

To get the search working, you need to find the block of code starting with the IF statement:
Code:
if ($vbulletin->GPC['ausername'])
.

When a quick search is done, the field 'ausername' contains the search string. All you need to do is update the condition variable to search fieldX rather than username.

Code:
	
if ($vbulletin->GPC['ausername'])
{	
	if($sortfield == 'lastname')
	{
		$condition  .=  " AND userfield.fieldX LIKE '%" . $db->escape_string_like(htmlspecialchars_uni($vbulletin->GPC['ausername'])) . "%' ";
	}
	else
	{
		$condition  .=  " AND username LIKE '%" . $db->escape_string_like(htmlspecialchars_uni($vbulletin->GPC['ausername'])) . "%' ";
	}
}
Note that I wrote this using vb 3.8.3.
Reply With Quote
  #4  
Old 10-19-2009, 02:50 PM
ganima ganima is offline
 
Join Date: Jul 2009
Posts: 6
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

There seems to be a problem with the field name. I get this MySQL error:
(...) Unknown column 'field7' in 'where clause' (...)

That is the part of my code:
PHP Code:
if ($sortfield == 'nachname'
            {
                
$condition 'field7 LIKE("' $db->escape_string_like($ltr) . '%")';
            }
            else
            {    
                
$condition 'username LIKE("' $db->escape_string_like($ltr) . '%")';
            } 
What's wrong with that? field7 is correct but the field name is not. I also tried to insert a variable like $userinfo[field7].

What is the right syntax here for the field name? Can anybody help?
Reply With Quote
  #5  
Old 10-27-2009, 04:34 PM
anthonym16 anthonym16 is offline
 
Join Date: Feb 2009
Posts: 12
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Prefix field7 with the table name. userfield.field7

There are a lot of joins in that query so you need to specify which table field7 comes from.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:55 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03787 seconds
  • Memory Usage 2,269KB
  • Queries Executed 18 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (2)bbcode_code
  • (7)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (6)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (4)postbit
  • (5)postbit_onlinestatus
  • (5)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete