The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Data From 2 Tables in one Query?
Hi all,
For my Toplist hack, I am implementing a rating system for it, and need to show the average rating of each of the sites on the main page. I am not sure how to do this, because the rating data is in a separate table. I know how to get the average, but don't know how to get it on the main page, which uses a while loop to show all the sites in the Toplist. The database structure is like this: Table: toplist_sites `id` `username` `name` `url` `description` `image` `in` `out` `status` Table: toplist_ratings `id` `site_id` `username` `rating` Any help is appreciated. Thanks, Derek |
#2
|
|||
|
|||
Test the following...
Code:
SELECT toplist_sites.*, AVG(toplist_ratings.rating) FROM toplist_sites, toplist_ratings WHERE toplist_sites.id = toplist_ratings.site_id GROUP BY toplist_ratings.site_id; |
#3
|
|||
|
|||
Thanks, I'll give it a try.
Derek EDIT: It doesn't work . It only shows one site instead of all of them. See here for what I mean - http://www.trafficsurfer.net/forums/toplist.php |
#4
|
|||
|
|||
Then you are not processing all rows returned. Please post the php script you are using to display this.
|
#5
|
|||
|
|||
Hi Marco,
Here is my toplist.php file: PHP Code:
Thanks, Derek |
#6
|
|||
|
|||
I find referencing 2 tables at once can be made much easier to understand by using aliases in your query, eg:
Code:
SELECT t1.field AS field1, t2.anotherfield AS field2 FROM user AS t1, post AS t2 WHERE t1.userid = t2.userid AND t2.postid = '11111' |
#7
|
|||
|
|||
Will that show all of the sites though? I need to show all the sites in the toplist_sites table, and their average rating, in the toplist_ratings table.
|
#8
|
|||
|
|||
Quote:
|
#9
|
|||
|
|||
Thanks!
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|