![]() |
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 |
Test the following...
Code:
SELECT toplist_sites.*, AVG(toplist_ratings.rating) |
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 |
Then you are not processing all rows returned. Please post the php script you are using to display this.
|
Hi Marco,
Here is my toplist.php file: PHP Code:
Thanks, Derek |
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' |
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.
|
Quote:
|
Thanks! :)
|
All times are GMT. The time now is 07:55 AM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|