Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 09-08-2005, 05:17 PM
dolbex dolbex is offline
 
Join Date: Aug 2005
Posts: 13
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Efficient way of querying buddy list

Ive been sitting here for an hour banging my head against the desk trying to figure out how to write a SQL statement that will return an array of users that are buddies on a specific user. I can pass the function the userid fine and I know that they reside in the vb3_usertextfield.buddylist field, I just don't know how to handle the contents so that I can then query the usernames without looping through an impload and querying for every single userid.

Any SQL junkies out there?
Reply With Quote
  #2  
Old 09-08-2005, 09:05 PM
Guest190829
Guest
 
Posts: n/a
Default

Why not just take vbulletin's code in profile.php? That's what I did ^_^
Reply With Quote
  #3  
Old 09-08-2005, 11:08 PM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I duno if there is a vb function, but try something like this (did it real quick, may contain errors):
PHP Code:
// Get Buddy List
$buddylist $vbulletin->db->query_first("
    SELECT buddylist
    FROM " 
TABLE_PREFIX "usertextfield
    WHERE userid = '" 
$userinfo['userid'] . "'
    LIMIT 1
"
);

// Convert to List
$buddies str_replace(" "","$buddylist['buddylist']);

// Get Their Usernames
$getbuddies $vbulletin->db->query_read("
    SELECT username, userid
    FROM " 
TABLE_PREFIX "user
    WHERE userid IN(0" 
$buddies ")
    ORDER BY username ASC
"
);

// Print out Each Buddy
while ($buddy $vbulletin->db->fetch_array($getbuddies))
{
    
$buddycounter++;
    
$comma = ($buddycounter 1) ? ", " "";
    echo 
$comma '<a href="member.php?u=' $buddy['userid'] . '">' .  $buddy['username'] . '</a>';

change $userinfo['userid'] to the userid of the user you want to get.
Reply With Quote
  #4  
Old 09-11-2005, 05:30 PM
dolbex dolbex is offline
 
Join Date: Aug 2005
Posts: 13
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks much SirAdrian works perfect. Had to modify it a little to play nicely with my db and functions but other than that it seems you were spot on. The only other request that I am getting is that it display which buddies are mutual. For instance. If I add you as a buddy and you add me as a buddy we are then mutual.

I have installed the "Who Am I a Buddy Of" Hack for the forum itself, but I can't seem to get the query to apply to my page. Basically I just want to display weather or not the buddy is mutual next to each buddy with a "(mutual)" output. LOL. Seems like its not a big deal but I am having a heck of a time trying to pull it off.

Thanks for all the help so far!
Reply With Quote
  #5  
Old 09-22-2005, 08:28 AM
dolbex dolbex is offline
 
Join Date: Aug 2005
Posts: 13
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I still have had no luck with figuring out an efficient way to figure out mutual buddies... anyone have a clue?

HTML Code:
SELECT userid
FROM vb3_usertextfield
WHERE FIND_IN_SET('".$uid."', REPLACE(buddylist, ' ', ',')) > 0
Remember that this was for a function outside vb and "$uid" should be replaced with $bbuserinfo[$uid] or whatever the variable is...

Dolbex
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 07:35 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.04078 seconds
  • Memory Usage 2,202KB
  • Queries Executed 13 (?)
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
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_html
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)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
  • (5)postbit
  • (4)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