By vosko on
Hi there
I'm trying to count the number of buddies by user
Have tried this snippet but I'm getting an error database (Column 'uid' in field list is ambiguous query...)
<?php
$buddycount = db_query('SELECT COUNT(uid) AS number FROM {buddylist} u JOIN {users} ur ON u.uid=ur.uid WHERE ur.status=1 AND u.received=1');
echo "Buddies: $buddycount <br>";
?>
Any solution?
Thanks in advance
Comments
suggestion
My sql knowledge is a little patchy, but have you tried changing the count from COUNT(uid) to COUNT(u.uid) ?
Cheers,
Thomas
(Coding bugs on a friday afternoon - not fun)
__________________________
http://www.thomasturnbull.com
http://twitter.com/thomasturnbull
Thanks for quick
Thanks for quick response
But the result is Resource id #245 in all my users.
Obviously I don't have 245 buddies by user, may be some day... ;)
And I have tried to put (ur.uid) instead of (uid) or (u.uid) but displays the same wrong data
Best
SELECT COUNT(ru.uid) AS
SELECT COUNT(ru.uid) AS number FROM {buddylist} u JOIN {users} ur ON u.uid=ur.uid GROUP BY ru.uid WHERE ur.status=1 AND u.received=1 AND u.uid=1notice the change of
uidtoru.uid, adding theGROUP BYclause, and adding a finalu.uid=????at the end (to limit the results to one user).I didn't try it, b/c I don't use this module, but it should work.
- Corey
Not solve the problem I'm
Not solve the problem
I'm getting again a mysql error:
Thanks for help
Try changing the order.
Try changing the order. I'll look again when I get back in town tonight.
SELECT COUNT(ru.uid) AS number FROM {buddylist} u JOIN {users} ur ON u.uid=ur.uid WHERE ur.status=1 AND u.received=1 AND u.uid=1 GROUP BY ru.uid- Corey
Again mysql error user
Again mysql error
user warning: Unknown table 'ru' in field list query: SELECT COUNT(ru.uid) AS number FROM buddylist u JOIN users ur ON u.uid=ur.uid WHERE ur.status=1 AND u.received=1 AND u.uid=1 GROUP BY ru.uidSometimes I wonder why I
Sometimes I wonder why I even try...
It's
ur, notru! I should've caught that. :-\I made a few other changes as well.
SELECT COUNT(u.uid) AS number FROM users ur LEFT JOIN buddylist u ON u.uid=ur.uid WHERE ur.status=1 AND u.received=1 AND u.uid=1 GROUP BY ur.uid- Corey
Resource id #245
Hi Corey
First of all thanks for your help
But again I'm geetting this weird data: Resource id #245.
Best
I think now the error is in
I think now the error is in your PHP code. Try this:
The SQL had to be changed, too, but if I also overlooked that PHP error, then I think I'll go shoot myself (or at least get more sleep!!!). :)
- Corey
blank result
Hi Corey
Trying your last code I'm getting a blank result, but if I delete u.uid=1 always list 1 buddy for all the users. And at least 2 users have 2 buddies
We are near...
Best
Solved count buddies by user
Hi there
Finally I have got it! I complicated too using INNER JOIN, LEFT JOIN and others variables....
For user-profile page you can use this snippet:
For front-page you can use this other snippet, combining with additional info as username and userpicture:
Best