Jump to content

[SOLVED] Order by top rated


balkan7

Recommended Posts

Hi

 

Looks like you need to do a join of the 2 tables, and count the number of resulting rows grouped by the entries on the photos table.

 

Something like this:-

 

SELECT photo_id, photo_name, photo_thumb, photo_file, photo_date, COUNT(*) AS RatingCount
FROM photos a JOIN ratings b ON a.photo_id = b.rating_item_id
GROUP BY photo_id, photo_name, photo_thumb, photo_file, photo_date
ORDER BY RatingCount

 

All the best

 

Keith

Thanks for your post,

but forgot that I pasted my query that should be little to be changed because not show me toprated.

 

SELECT tp.*, SUM(tr.rating_vote) AS sum_rating, COUNT(tr.rating_item_id) AS count_votes
				FROM ".DB_PHOTOS." tp
				LEFT JOIN ".DB_RATINGS." tr ON tr.rating_item_id = tp.photo_id AND tr.rating_type='P'
				GROUP BY photo_id ORDER BY count_votes DESC LIMIT ".$_GET['rowstart'].",".$settings['thumbs_per_page']

Hi

 

Looks like you need to do a join of the 2 tables, and count the number of resulting rows grouped by the entries on the photos table.

 

Something like this:-

 

SELECT photo_id, photo_name, photo_thumb, photo_file, photo_date, COUNT(*) AS RatingCount
FROM photos a JOIN ratings b ON a.photo_id = b.rating_item_id
GROUP BY photo_id, photo_name, photo_thumb, photo_file, photo_date
ORDER BY RatingCount

 

All the best

 

Keith

i have to try whit this one but again whiout result:

SELECT tp.*, ta.*, SUM(tr.rating_vote) AS sum_rating, COUNT(tr.rating_item_id) AS count_votes
	FROM ".DB_PHOTOS." tp
	LEFT JOIN ".DB_PHOTO_ALBUMS." ta USING (album_id)
	LEFT JOIN ".DB_RATINGS." tr ON tr.rating_item_id = tp.photo_id AND tr.rating_type='P'
	GROUP BY tp.photo_id ORDER BY count_votes DESC LIMIT ".$_GET['rowstart'].",".$settings['thumbs_per_page']

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.