tags:

views:

31

answers:

2

I'm creating a table called news_feed, this will log all the actions a user performs.

Lets say I want to store

user1234 deleted article412 at midday

I then need a table like so

timestamp | user_id | subject_type | subject_id | method

.

there would be 5 potential methods to log,

methods = add/edit/delete/update/report

and lets say 2 possible subject_type

subjects = article/comment

I know i could make my own key where 0=add, 1=delete etc etc but this would make my queries cumbersome to use/write as i'd need to keep consulting the key. Is there a MySql type which can read lots of identially values quickly? is this ENUM? how do i use it?!!

+1  A: 

Why don't you take a look at the docs? It's explained quite well there.

RaYell
+3  A: 

Yes, you can use the ENUM type for this.

CREATE TABLE news_feed (
    ...
    methods ENUM('add', 'edit', 'delete', 'update', 'report'),
    subjects ENUM('article', 'comment')
);

Then just use at as you would any other field, e.g.

SELECT * FROM news_feed WHERE methods='add';

The documentation for the ENUM type has much more info.

Rich Adams
is there an easy way to do this with phpmyadmin?
Haroldo
got it, put the potential values in the (length/values) col
Haroldo
When creating a table in phpmyadmin, just select ENUM from the "Type" dropdown, and then in the "Length/Value" box put the values in single quotes separated by commas. e.g. 'add','edit' etc.
Rich Adams
Yup, you got it, that's the one.
Rich Adams