Есть один скриптик голосования. В базе, в таблитце votionы хранится все данные голосование.
Вот пример:
Код |
votion_id brand_id criteria_id user_id rate date 1 1 1 NULL 1 2007-04-23 2 2 2 NULL 1 2007-04-23 3 1 3 NULL 1 2007-04-23 4 1 4 NULL 1 2007-04-23 5 2 5 NULL 1 2007-04-23 6 2 6 NULL 1 2007-04-23 7 1 7 NULL 1 2007-04-23 8 1 8 NULL 1 2007-04-23 9 2 9 NULL 1 2007-04-23 10 1 10 NULL 1 2007-04-23 11 2 1 NULL 1 2007-04-23 12 2 2 NULL 1 2007-04-23 13 2 3 NULL 1 2007-04-23 14 1 4 NULL 1 2007-04-23 15 2 5 NULL 1 2007-04-23 16 1 6 NULL 1 2007-04-23 17 1 7 NULL 1 2007-04-23 18 2 8 NULL 1 2007-04-23 19 1 9 NULL 1 2007-04-23 20 1 10 NULL 1 2007-04-23 |
Код |
1. для 7 дней SELECT sum( rate ) AS rates, brand_id, date FROM votions GROUP BY date ORDER BY date DESC LIMIT 7 2. для 30 дней SELECT sum( rate ) AS rates, brand_id, date FROM votions GROUP BY date ORDER BY date DESC LIMIT 30 |
Код |
1. для 7 дней SELECT sum( rate ) AS rates, brand_id, date FROM votions GROUP BY date ORDER BY date DESC LIMIT 7 2. для 30 дней SELECT sum( rate ) AS rates, brand_id, date FROM votions GROUP BY date ORDER BY date DESC LIMIT 30 |