View Full Version : Adding Referral Count to User Stats
esawdust
11-09-2002, 09:24 PM
Hi folks,
How would I go about adding "Referrals:" to the user stats at left (locatin, registered since, and posts, etc..)
I have installed the Refer Friends hack and want to add the # of referrals to this info. Also is there a variable ($referrals ??) that would present the users total referrals within the user stats on every post.
Thanks for any help.
Greg
Erwin
11-10-2002, 03:15 AM
Not tested myself, but should work - try this:
In functions.php, find:
$post[off]=bbcodeparse($post[off],0,$allowsmilies);
UNDERNEATH, add:
// Get referrals
if ($usereferrer) {
$refcount = $DB_site->query_first("SELECT count(*) AS count
FROM user
WHERE referrerid = '$post[userid]'");
$referrals = $refcount[count];
}
Then, in your postbit, add this anywhere you like to show the referral count:
Referrals: #$referrals
Should work! However, this will add an extra query per post in a thread to the showthread page. There's no real way around this unfortunately, since the referral count needs a query to COUNT the variable from the database. :)
esawdust
11-10-2002, 03:15 PM
Thanks for your reply Erwin!
I looked and looked for the snippet of code (an probably missed it :cross-eyed: ) to no avail.. (functions.php in VB 2.2.8)
Can you give me an idea where it may be? I did post the code on the 248-255 but it didn't work.
I have the postbit taken care of.
Here's my code:
$post[useremail]="";
$post[icqicon]="";
$post[aimicon]="";
$post[yahooicon]="";
$post[homepage]="";
$post[findposts]="";
$post[signature]="";
$onlinestatus="";
}
// Get referrals
if ($userreferrer) {
$refcount = $DB_site->query_first("SELECT count(*) AS count
FROM user
WHERE referrerid = '$post[userid]'");
$referrals = $refcount[count];
}
// do ip addresses
if ($post[ip]!="") {
if ($logip==2) {
Seeing as how the user profile pulls the referrals already (assuming it's activated in vB) is there a $string already set that could be placed in the postbit? Or is that all done through a query also?
Thanks a bunch!
Greg
esawdust
11-10-2002, 11:05 PM
bump
Erwin
11-10-2002, 11:10 PM
Put the code in functions.php exactly where I say to put it - that line of code was taken from functions.php 2.2.8 unhacked - and then remember to edit your postbit template. It should work.
The referral count needs to be specifically queried from the database for the postbit.
esawdust
11-10-2002, 11:59 PM
Okay... I still cannot find that "exact" line of code. I even performed a find and replace in Dreamweaver after manually scrolling 2300 plus lines and it wasn't found. Then I pulled a fresh vb.zip for the functions.php file (figuring maybe a hack modified it) and still no match.
Either I'm nuts, blind, or that code is not in there :) There is no code that starts with $post[off] whatsoever in the functions.php version 2.2.8.
Please advise?!?
Thanks for your time,
Greg
Erwin
11-11-2002, 12:23 AM
Sorry, vB.org parsed the code I used.
Try to find this in functions.php instead:
eval("\$post[profile] = \"".gettemplate("postbit_profile")."\";");
Add my code ABOVE this.
See if that works.
esawdust
11-11-2002, 04:53 PM
Okay.. found the code :) but it didn't work :( The Referrals: # shows up in my postbit but it's not logging the $referrals number.
} else {
$post[pmlink] = "";
}
// Get referrals
if ($usereferrer) {
$refcount = $DB_site->query_first("SELECT count(*) AS count
FROM user
WHERE referrerid = '$post[userid]'");
$referrals = $refcount[count];
}
eval("\$post[profile] = \"".gettemplate("postbit_profile")."\";");
eval("\$post[search] = \"".gettemplate("postbit_search")."\";");
eval("\$post[buddy] = \"".gettemplate("postbit_buddy")."\";");
<smallfont>Registered: $post[joindate]<br>
Location: $post[field3]<br>
Posts: $post[posts]<br>
Total Referrals:#$referrals<br><br>
Certifications: <br>$badge $badge2 $badge3<br>
$onlinestatus</smallfont></td>
<td bgcolor="$post[backcolor]" width="100%"
Erwin
11-11-2002, 05:01 PM
Try this code instead:
// Get referrals
$refcount = $DB_site->query_first("SELECT count(*) AS count FROM user WHERE referrerid = '$post[userid]'");
Put that where you tried the other code.
Then, in your postbit template, try this:
Referrals: #$refcount[count]
esawdust
11-11-2002, 05:09 PM
Hi Erwin,
I made the changes... now when I click on a thread it gives me:
Fatal error: Call to a member function on a non-object in /public_html/forums/admin/functions.php on line 228
Thanks again.
Erwin
11-11-2002, 08:26 PM
Did you paste that in the right place? Your error message does not correlate with the query.
NTLDR
11-11-2002, 08:40 PM
You need to make sure you have $DB_site listed with the globals at the top of the buildpostbit function.
Erwin
11-11-2002, 08:51 PM
Do this:
In functions.php -
Find:
// ###################### Start buildpostbit #######################
Underneath, add:
global $DB_site
Like I said, this is usually not done because you don't want to add 1 query per post per thread. But you wanted it.
esawdust
11-12-2002, 12:10 AM
Parse error: parse error, expecting `','' or `';'' in /public_html/forums/admin/functions.php on line 59
Fatal error: Call to undefined function: getuserinfo() in /public_html/forums/admin/sessions.php on line 365
Well :) ... I added the additonal piece of code as stated and it gave me the above errors. I also double checked the original code and all is in the locations you specified.
My intent for the count was to promote refers through a points/awards system. At 10 referal they can earn something, 25 points... and so on. I wanted to display it within the user stats to entice a competitive spirit :)
Maybe there's a better way of doing this?
Thanks again!
Greg
NTLDR
11-12-2002, 06:14 PM
Make sure theres a ; on the end, ie:
global $DB_site;
esawdust
11-12-2002, 06:55 PM
Fatal error: Call to a member function on a non-object in /public_html/forums/admin/functions.php on line 230
:) Back down to one error .....
Greg
esawdust
11-12-2002, 07:02 PM
I tried this with the first bit of code Erwin posted as well.. didn't work. Although there are no errors and everything works fine... just no referrals #
Greg
xXoOmegaoXx
01-28-2003, 10:42 PM
did you paste "Referrals : #$referals;"?
IF you did, you ARE supposed to take out the pound (#) symbol ;)
Dean C
01-29-2003, 03:24 PM
That's irrelevant buddy ^ the # is just what will apeare in the postbit template so it will like this:
Referrals: #4
- miSt
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.