开发者

Retrieve daily competition entries grouped by member

this is a followup to my previous question, whereby I'm writing a PHP competition script for a members site that restricts entries to one per day per member.

The entries are stored in a table "competition_entries" with the following structure:

ce_id: primary key 
ce_c_id: competition ID
ce_sub_id: member ID
ce_date: date stamp for the entry

I would like to write a MySQL query that retrieves number of entries per member, i.e.

Member A: 4 entries
Member C: 2 entries
Member Y: 23 entries
etc...

but am struggling as to how to do so. TIA.

EDIT: In case it's not obvious, I realise I need to relate the member ID back to another table to retri开发者_C百科eve their username - that bit I can do (sorry, long day) :)


I think this query should do it for you:

SELECT COUNT(ce_sub_id) FROM competition_entries 
WHERE ce_c_id = '$competition_id' 
GROUP BY ce_sub_id

You should have a result set with a member id and the number of entries he or she has made. You can then loop through your results, and output them in the format you described.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜