Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Dec 2008
    Posts
    120
    Thanks
    15
    Thanked 2 Times in 2 Posts

    Status field within the DB!

    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!

  • #2
    Regular Coder lokeshshettyk's Avatar
    Join Date
    Aug 2008
    Location
    On the way to the moon!
    Posts
    157
    Thanks
    5
    Thanked 20 Times in 20 Posts
    If i were to do this, I would use "views"....

    for example (run the below on your DB which would create the view),
    Code:
    CREATE view status_1 as select * from tablename where status = 1;
    Then while you query the DB from php/jsp whatever, use

    Code:
    select * from status_1;
    More here http://dev.mysql.com/doc/refman/5.0/en/create-view.html
    _______________________________________________________________________________________
    Thank the user for his/her helpful post by clicking on the button below the post :)

    Cheers :)
    ~ LSK ~

  • Users who have thanked lokeshshettyk for this post:

    muneeba9071 (02-16-2009)

  • #3
    Regular Coder
    Join Date
    Dec 2008
    Posts
    120
    Thanks
    15
    Thanked 2 Times in 2 Posts
    Thats the trick I been looking for, thanks


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •