The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Please help with query.
Well I'm trying to get the overall feedback rating from photopost classifieds to show in the vbulletin profile page.
So I've made a file called getfeedback.php and put it in my includes folder for vb. Then in the member.php file for vbulletin I've put this getfeedback.php as require_once(DIR . '/includes/getfeedback.php'); In the getfeedback.php file I have the following code. Code:
<?php $dbhost = 'localhost'; $dbuser = 'database_username'; $dbpass = 'database_password'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'database_name'; mysql_select_db($dbname); $query = "SELECT foruser, rating, username FROM cp_feedback WHERE rating = 3 AND foruser = 6"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $ratingPosTotal += 1; } $query = "SELECT foruser, rating, username FROM cp_feedback WHERE rating = 1 AND foruser = 6"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $ratingNegTotal += 1; } $feedbackRatingTotal = $ratingPosTotal - $ratingNegTotal; ?> So then in my MEMBERINFO template for vb I have added a line that will show $userinfo[username]'s Feedback Rating: $feedbackRatingTotal and then this will show the users feedback rating score. But where I have this code: Code:
AND foruser = 6"; I don't really know much about php so can someone help me, what would I insert to make it be AND foruser = whatever userid of the profile I'm looking at? I've tried just about everything I can think of but nothing is working. |
#2
|
||||
|
||||
$userinfo[userid]
|
#3
|
|||
|
|||
I tried that and it didn't work, guessing that $userinfo[userid] isn't assigned until later in the member.php file? (after I require_once the file that I want to use it)
I was able to put the query right into the member.php file and get it to work correctly, but I'd like to just keep it a seperate file so I don't need to have the original code changed too much. |
#4
|
||||
|
||||
Are you manually editing member.php? There are plenty of hooks available for you to use...
|
#5
|
||||
|
||||
Not sure where and when $userinfo is declared, but $vbulletin->userinfo should always be available.
Hurray for code-editing. There should be more if it! EDIT: Actually I notice you are not including global.php. You should be using the vb mysql object. I also have a feeling that global $userinfo (after importing global) should help. |
#6
|
||||
|
||||
Quote:
He doesn't need to include global.php, he's already inside member.php. But yes, he should be using the vBulletin DB object. |
#7
|
||||
|
||||
Quote:
It never hurts to put in a require_once, or at least check that the script in included after globals. |
#8
|
|||
|
|||
Oh wow.. didn't even know about $vbulletin->userinfo... Thanks a ton, this will help on another that I'm using.
So instead of editing these files, I can use hooks? I'll have to look into that. Thanks for the help guys, this is great. --------------- Added at 18:47 --------------- Wow... thanks for the tip on the hooks. I had no idea, this is SOOOOO much better and easier to figure out. So when I upgrade vbulletin stuff will my hooks still work? |
#9
|
||||
|
||||
Yes, if the hooks in the files don't get changed around.
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|