Re: NULLS vs Empty result in PHP
| From: | Jim Lucas | Date: | Wed, 23 Sep 2009 14:42:09 +0000 |
| Subject: | Re: NULLS vs Empty result in PHP | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-298284@lists.php.net to get a copy of this message | ||
Dan Shirah wrote:
> Morning!
>
> Just a quick question.
>
> Say I have a column in my database that could contain NULLS, empty spaces,
> or an actual value.
>
> If I do:
>
> $my_query = "SELECT my_column FROM my_database WHERE 1 = 1";
> $my_result = ifx_query($my_query, $connect_id);
>
> while($row = ifx_fetch_row($my_result)) {
> $my_column = trim($row['my_column']);
>
> if ($my_column != "") {
> echo "Test";
> }
> }
>
> The way PHP assigns the query results to the $my_column variable, wouldn't;
> if ($my_column != "") not do anything for the rows that contained NULLS or
> empty spaces?
>
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.