View Full Version : Status field within the DB!

02-16-2009, 01:57 PM

I have a field in a database called "status", if the status is 1, this means the item is active, if the status is 0, means the item is cancelled.

Now, everytime I have to mention in each queries, lets say, I want to show all items which are active I do "WHERE status = '1' ", my question is, is there possibility if we could put these restrictions within the database, so by default it shows all the active items... and if I want to see the cancelled items I will have to "WHERE status = '0' "


02-16-2009, 02:08 PM
If i were to do this, I would use "views"....

for example (run the below on your DB which would create the view),

CREATE view status_1 as select * from tablename where status = 1;

Then while you query the DB from php/jsp whatever, use

select * from status_1;

More here http://dev.mysql.com/doc/refman/5.0/en/create-view.html

02-16-2009, 02:30 PM
Thats the trick I been looking for, thanks :)