vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Efficient way of querying buddy list (https://vborg.vbsupport.ru/showthread.php?t=95876)

dolbex 09-08-2005 05:17 PM

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? :)

Guest190829 09-08-2005 09:05 PM

Why not just take vbulletin's code in profile.php? That's what I did ^_^

Adrian Schneider 09-08-2005 11:08 PM

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.

dolbex 09-11-2005 05:30 PM

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!

dolbex 09-22-2005 08:28 AM

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


All times are GMT. The time now is 02:57 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.00989 seconds
  • Memory Usage 1,726KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_html_printable
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete