SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist lirux's Avatar
    Join Date
    Jan 2001
    Location
    Lisboa : Portugal
    Posts
    418
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A field with a numeric value or unlimited

    I need a field to have a numeric value, or a value representing unlimited.
    Is it better to make this a numeric type field and use NULL for unlimited (i'm a bit worried about null!=0, since a very common value in this field would be 0), or simply making it a varchar - but only as a backup alternative since since i'd like to be able to, for instance, do a query where field>0 and stuff like that - I can't do that on a varchar, can I?
    So basically I'm looking for some pointers for how to differentiate between having null as the value, and 0 as the value, both in mysql and php.

    If anyone can throw me some tips it'd help me a lot!
    Duarte Carrilho da Graša
    RailsHelp.com: Searchable Rails reference
    CACA: Committee for the Annihilation of Complicated Acronyms

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,247
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    null and 0 are totally different, so you're okay
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Evangelist lirux's Avatar
    Join Date
    Jan 2001
    Location
    Lisboa : Portugal
    Posts
    418
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks!!
    Duarte Carrilho da Graša
    RailsHelp.com: Searchable Rails reference
    CACA: Committee for the Annihilation of Complicated Acronyms

  4. #4
    SitePoint Guru asterix's Avatar
    Join Date
    Jun 2003
    Posts
    847
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You will have problems in PHP if you try to equate NULL and 0.
    Because, if you say:

    $var = NULL;
    $var1 = 0;

    Then:
    ($var==$var1)=True.

    In PHP (Not SQL) the following truth table holds:
    (NULL == NULL) = True
    (NULL == FALSE) = True
    (NULL == TRUE) = False


Bookmarks

Posting Permissions

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