PHP Check for NULL

后端 未结 5 539
后悔当初
后悔当初 2020-11-30 11:04

Here is the below Code:

$query = mysql_query(\"SELECT * FROM tablex\");

if ($result = mysql_fetch_array($query)){

    if ($result[\'column\'] == NULL) { pr         


        
相关标签:
5条回答
  • 2020-11-30 11:15

    Sometimes, when I know that I am working with numbers, I use this logic (if result is not greater than zero):

    if (!$result['column']>0){
    
    }
    
    0 讨论(0)
  • 2020-11-30 11:16

    I think you want to use

    mysql_fetch_assoc($query)
    

    rather than

    mysql_fetch_row($query)
    

    The latter returns an normal array index by integers, whereas the former returns an associative array, index by the field names.

    0 讨论(0)
  • 2020-11-30 11:21

    Use is_null or === operator.

    is_null($result['column'])
    
    $result['column'] === NULL
    
    0 讨论(0)
  • 2020-11-30 11:36

    Make sure that the value of the column is really NULL and not an empty string or 0.

    0 讨论(0)
  • 2020-11-30 11:40

    How about using

    if (empty($result['column']))

    0 讨论(0)
提交回复
热议问题