I want user_id 2 to have an overview of the last action taken by another user on his account, any of
- vote up
- vote down
- confirm
- unconfirm
Each time a user takes an action a line is added with 1 in the right column. Blank elements are filled with 0.
user is the voter, user_id is the person voted on
| id | user | user_id | up | down | confirm | unconfirm | date |
+----+------+---------+----+------+---------+-----------+------------+
| 1 | 1 | 2 | 1 | | | | 2014-11-03 |
| 2 | 1 | 2 | 1 | | | | 2014-11-03 |
| 3 | 1 | 2 | | 1 | | | 2014-11-03 |
| 4 | 1 | 2 | | 1 | | | 2014-11-03 |
| 5 | 1 | 2 | | 1 | | | 2014-11-03 |
| 6 | 1 | 2 | 1 | | | | 2014-11-03 |
| 7 | 1 | 2 | | | 1 | | 2014-11-03 |
| 8 | 1 | 2 | | | | 1 | 2014-11-03 |
| 9 | 1 | 2 | | | 1 | | 2014-11-03 | //THIS
| 10 | 1 | 2 | 1 | | | | 2014-11-03 | // THIS
| 11 | 3 | 2 | | 1 | | | 2014-11-03 |
| 12 | 3 | 2 | 1 | | | | 2014-11-03 | //THIS
| 13 | 3 | 2 | | | 1 | | 2014-11-03 | // THIS
+----+------+---------+----+------+---------+-----------+------------+
OUTPUT: the last up or down, the last confirm or unconfirm from each user
- User 3 confirmation,
- User 3 Up,
- User 1 up,
- User 1 confirm.
SELECT * FROM table WHERE user_id = 2 GROUP BY .. ORDER BY id DESC
if($data['up'] == '1')
{
echo "You have been voted up ... You've earned..";
}
else if($data['down'] == '1')
{
echo "You have been voted down ... now you need to..";
}
...