...

View Full Version : Status field within the DB!



muneeba9071
02-16-2009, 02:57 PM
Hi,

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' "

Thanks!

lokeshshettyk
02-16-2009, 03: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

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum