PDA

View Full Version : Please help with query.


coralnutz
09-24-2007, 04:16 AM
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.


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

AND foruser = 6";

it will obviously show the feedback rating for userid number 6, no matter who's profile your looking for. (this works, depending on what number I put in, it will work to the point of showing that users feedback rating)

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. :(

Dismounted
09-24-2007, 05:05 AM
$userinfo[userid]

coralnutz
09-24-2007, 05:09 AM
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.

Dismounted
09-24-2007, 05:17 AM
Are you manually editing member.php? There are plenty of hooks available for you to use...

Eikinskjaldi
09-24-2007, 05:32 AM
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.

Dismounted
09-24-2007, 05:44 AM
Not sure where and when $userinfo is declared, but $vbulletin->userinfo should always be available.
$vbulletin->userinfo is the logged-in user's info. $userinfo is the profile your viewing's info.
Actually I notice you are not including global.php. You should be using the vb mysql object.
He doesn't need to include global.php, he's already inside member.php. But yes, he should be using the vBulletin DB object.

Eikinskjaldi
09-24-2007, 08:52 PM
He doesn't need to include global.php, he's already inside member.php. But yes, he should be using the vBulletin DB object.

Seriously dismounted, you know for a fact he is including them in the right order???

It never hurts to put in a require_once, or at least check that the script in included after globals.

coralnutz
09-25-2007, 09:23 PM
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. :D

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

Dismounted
09-26-2007, 06:38 AM
Yes, if the hooks in the files don't get changed around.