$referrals = $db->query_first(" SELECT username, userid FROM " . TABLE_PREFIX . "user WHERE referrerid = '".$userinfo['userid']."' "); $userinfo['referralname'] = $referrals[username]; $userinfo['referralid'] = $referrals[userid];
Announcement
Collapse
No announcement yet.
db->fetch_array question
Collapse
X
-
If you wanted to pull more than 1 piece if info from a query, I know you use db->fetch_array, but I'm not sure how you would use it. In this example:
Code:vBulletin - Sometimes, I'm just like, Wow, and then I'm like, Whoa, and then I'm like, Damn.
vBulletin.org's ol' Moderator
I have a lifetime terrorist hunting permit - #091101
chmod a+x /bin/laden -- Allows anyone the permission to execute /bin/ladenTags: None
-
Bob,
Use $db->query_read instead for arrays.
Then use while or foreach to loop through the array.
Regards,
Mosh.-- Wolfshead Solutions - Closed down permanently as of 1/7/2013.
-- As of 1/7/2013, due to medical reasons I no longer support my vbulletin.org hacks as I have left the vBulletin community.
-- My Free vBulletin.org Hacks
-
Originally posted by Mosh View PostBob,
Use $db->query_read instead for arrays.
Then use while or foreach to loop through the array.
Regards,
Mosh.
Code:$referrals = $db->query_read(" SELECT username, userid FROM " . TABLE_PREFIX . "user WHERE referrerid = '".$userinfo['userid']."' "); while ($referral = $db->fetch_array($referrals)) { $ref['referralname'] .= ", $referral[username]"; $ref['referralid'] .= $referral[userid]; } $db->free_result($referrals); $userinfo['referralname'] = ltrim($ref[referralname], ', '); $userinfo['referralid'] = $ref[referralid];
Last edited by Boofo; Wed 9th Jun '10, 4:39am.vBulletin - Sometimes, I'm just like, Wow, and then I'm like, Whoa, and then I'm like, Damn.
vBulletin.org's ol' Moderator
I have a lifetime terrorist hunting permit - #091101
chmod a+x /bin/laden -- Allows anyone the permission to execute /bin/laden
Comment
-
You are going to need to construct your rows first in the while loop, then spit out the results after - if you look at code that utilises the misc_start hook of my Who Has Rated A Thread you will get the gist of what I am on about.-- Wolfshead Solutions - Closed down permanently as of 1/7/2013.
-- As of 1/7/2013, due to medical reasons I no longer support my vbulletin.org hacks as I have left the vBulletin community.
-- My Free vBulletin.org Hacks
Comment
-
Originally posted by Mosh View PostYou are going to need to construct your rows first in the while loop, then spit out the results after - if you look at code that utilises the misc_start hook of my Who Has Rated A Thread you will get the gist of what I am on about.
I guess it will have to do with just pulling the names and not trying to link them to their profile. Thank you, anyway, sir.vBulletin - Sometimes, I'm just like, Wow, and then I'm like, Whoa, and then I'm like, Damn.
vBulletin.org's ol' Moderator
I have a lifetime terrorist hunting permit - #091101
chmod a+x /bin/laden -- Allows anyone the permission to execute /bin/laden
Comment
-
I finally got it, although I'm sure there is a cleaner way to do it. This is what I ended up with:
Code:if ($vbulletin->options['usereferrer'] AND !$userinfo['referrerid']) { $referrals = $db->query_read(" SELECT username, userid FROM " . TABLE_PREFIX . "user WHERE referrerid = '".$userinfo['userid']."' "); while ($referral = $db->fetch_array($referrals)) { $ref['referralname'] .= ", <a href=\"member.php?u=$referral[userid]\">$referral[username]</a>"; } $db->free_result($referrals); $userinfo['referralname'] = ltrim($ref[referralname], ', '); }
HTML Code:<dd>{vb:raw userinfo.referralname}</dd>
vBulletin - Sometimes, I'm just like, Wow, and then I'm like, Whoa, and then I'm like, Damn.
vBulletin.org's ol' Moderator
I have a lifetime terrorist hunting permit - #091101
chmod a+x /bin/laden -- Allows anyone the permission to execute /bin/laden
Comment
-
Mosh and I were discussing this earlier and I have a question for the devs. Which way is less server intensive if you have 1000 referred members? The vb way of doing it (first code):
Code:while ($referral = $db->fetch_array($referrals)) { $templater = vB_Template::create('boofo_referral_bit'); $templater->register('referral', $referral); $referral_row .= $templater->render(); } $db->free_result($referrals); $userinfo['referralname'] = ltrim($referral_row, ', ');
Code:while ($referral = $db->fetch_array($referrals)) { $ref['referralname'] .= ", <a href=\"member.php?$session[sessionurl]$referral[userid]-$referral[username]\">$referral[username]</a>"; } $db->free_result($referrals); $userinfo['referralname'] = ltrim($ref[referralname], ', ');
I would think not having to render a template for every username would be faster and less server intensive. But I could be wrong. Any suggestions?vBulletin - Sometimes, I'm just like, Wow, and then I'm like, Whoa, and then I'm like, Damn.
vBulletin.org's ol' Moderator
I have a lifetime terrorist hunting permit - #091101
chmod a+x /bin/laden -- Allows anyone the permission to execute /bin/laden
Comment
-
Originally posted by ragtek View PostTry it out^^
place a timer before you start the while part and one after the while part, then you can see how long it took
and in the debug info you can see how many memory,etc is neededvBulletin - Sometimes, I'm just like, Wow, and then I'm like, Whoa, and then I'm like, Damn.
vBulletin.org's ol' Moderator
I have a lifetime terrorist hunting permit - #091101
chmod a+x /bin/laden -- Allows anyone the permission to execute /bin/laden
Comment
-
I'm using xdebug for this (xdebug_time_index()) but i think this would be too difficult to explain.
=> Instead use microtime
PHP Code:$timeStartComma = microtime(true);
//now do something, for example the while part
$timeEndComma = microtime(true);
echo "Part needed " . ($timeEndComma-$timeStartComma) . " seconds\n";
Comment
-
Originally posted by ragtek View PostI'm using xdebug for this (xdebug_time_index()) but i think this would be too difficult to explain.
=> Instead use microtime
PHP Code:$timeStartComma = microtime(true);
//now do something, for example the while part
$timeEndComma = microtime(true);
echo "Part needed " . ($timeEndComma-$timeStartComma) . " seconds\n";
Thanks, but I'll wait for a dev or someone who knows that can tell me by looking at the code I posted.vBulletin - Sometimes, I'm just like, Wow, and then I'm like, Whoa, and then I'm like, Damn.
vBulletin.org's ol' Moderator
I have a lifetime terrorist hunting permit - #091101
chmod a+x /bin/laden -- Allows anyone the permission to execute /bin/laden
Comment
-
None of the devs or crack coders has an opinion on this?vBulletin - Sometimes, I'm just like, Wow, and then I'm like, Whoa, and then I'm like, Damn.
vBulletin.org's ol' Moderator
I have a lifetime terrorist hunting permit - #091101
chmod a+x /bin/laden -- Allows anyone the permission to execute /bin/laden
Comment
-
I have another question concerning this. Do you need to declare an array if you are only using the while and not using a foreach? As in the following?
Code:$ref = array(); while ($referral = $vbulletin->db->fetch_array($referrals)) { $ref['referralname'] .= ", <a href=\"member.php?$session[sessionurl]$referral[userid]-$referral[username]\">$referral[username]</a>"; } unset($referral); $vbulletin->db->free_result($referrals);
vBulletin - Sometimes, I'm just like, Wow, and then I'm like, Whoa, and then I'm like, Damn.
vBulletin.org's ol' Moderator
I have a lifetime terrorist hunting permit - #091101
chmod a+x /bin/laden -- Allows anyone the permission to execute /bin/laden
Comment
widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
Comment