Jump to content

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']

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.