Re: NULLS vs Empty result in PHP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Sep 23, 2009 at 11:35 AM, Philip Thompson
<philthathril@xxxxxxxxx> wrote:
> On Sep 23, 2009, at 9:48 AM, Dan Shirah wrote:
>
>>>
>>> From reading the other responses to this thread, it seems that you want
>>> to
>>> "skip" or "exclude" rows in the results where my_column === null.
>>>
>>> If this is correct, why not do it in the SELECT statement to begin with?
>>>
>>> $my_query = "SELECT my_column FROM my_database WHERE my_column IS NOT
>>> NULL";
>>>
>>> That should do it.
>>>
>>
>> I want to exclude the rows that might be NULL, "" (empty), or "        "
>> (empty series of spaces)
>>
>> From all of the input so far, it seems that using trim() on the variable
>> and
>> then use empty() is the best way to pick all three types up.
>
> I don't think you're using mysql, but your selected db may have a similar
> option. I would do the work in the sql.
>
> <?php
> $sql = "SELECT * FROM `table` WHERE TRIM(`column`) <> '' AND `column` IS NOT
> NULL";
> $result = query($sql);
> while ($row = fetch_row ($result)) {
>    echo "Not empty, multiple spaces or NULL!";
> }
> ?>
>
> So, if you have any extraneous spaces, they will be removed. It also
> accounts for nulls. No work is required by PHP to determine the values you
> need. Just use what it returns. This should work.
>
> Hope this helps.
> ~Philip
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Another thought might be to convert the nulls into another value

select field1, field2, ISNULL(field3,'-') from table where ...

would convert the nulls into hyphens

-- 

Bastien

Cat, the other other white meat

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux