Does TinyInt '0' equal NULL?

Discussion in 'MySQL' started by frobak, Feb 13, 2012.

  1. #1
    Does a TINYINT value of 0 equal NULL when selecting from the cell? I though it would equal false.

    A little background:

    I am searching a table for selected checkboxes and then comparing that with posted php data:

    
    $sql = "SELECT username FROM candidate_details WHERE
    		acca= '$_POST[acca]' OR
    		msc_bp_mgmt = '$_POST[msc_bp_mgmt]'OR
    
    Code (markup):
    So I want the username pulled out if the cells match.

    If the checkbox on the form submitted was not selected, '$_POST[acca]' would be null.

    And then when i compare that to the candidate_details table cell, which has a value of '0' - (zero) - it is still coming up as a match?

    Is this right?

    Or is there another data type that actually enters TRUE or FALSE from a checkbox selection?

    help much appreciated

    Cheers
     
    frobak, Feb 13, 2012 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    If you are referring to php, then yes 0 would evaluate as null. If you need to compare with a zero use === or !== instead of == and !=.
     
    jestep, Feb 13, 2012 IP
  3. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #3
    In a database, NULL means a field in which (for that record) no data has ever been entered. It's not the same as '' for a char field or 0 for a numeric field. If you enter '' in a char field or 0 in a numeric field it's not NULL.
     
    Rukbat, Feb 25, 2012 IP
  4. GodOfTerror

    GodOfTerror Peon

    Messages:
    41
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    NULL means empty, not even "0".
    "0" would be a digit, it might be a choice of "default"

    for example if featured item should be set to "1"
    then by default all items should be set to "0" or "2"

    0 is just as good as "2" or any number because
    it can be used to identify the data.

    - Sumer Kolcak
     
    GodOfTerror, Mar 11, 2012 IP