Forum Moderators: coopster

Message Too Old, No Replies

if statement help

         

fzx5v0

4:07 pm on Apr 4, 2006 (gmt 0)

10+ Year Member



Hi

i need to query a certain feild in a mysql database and if it has no value in it then prefom action but i have tried all day with no sucess on how to do this

can anyone advise

for example

$category_query = tep_db_query ("select title from " . TABLE_META_TAGS . " where categories_id = '" . $metaCategory . "'");

if title has no value in the field the echo 12345678

else
echo title

Thanks for any advise

BarryStCyr

4:28 pm on Apr 4, 2006 (gmt 0)

10+ Year Member



I don't know what you have tried, but have you tried the IS_NULL function in php?

Like
if(is_null(<<FIELD>>))
{
echo "12345678";
}

Barry

fzx5v0

5:16 pm on Apr 4, 2006 (gmt 0)

10+ Year Member



Hi thanks for the reply I am new to php this is what I have and i do not understand why it only does the else not the first bit when the field is empty

<?php
$category_query = tep_db_query ("select title from " . TABLE_META_TAGS . " where categories_id = '" . $metaCategory . "'");
if(is_null($category_query))
{
?>
<?php
require(DIR_WS_INCLUDES . 'meta_tags.php');
?>
<?php
}
else
{
(DIR_WS_INCLUDES . 'meta_tags1.php')) {
require(DIR_WS_INCLUDES . 'meta_tags1.php');
} //else {
?>

thanks in advance

jatar_k

6:23 pm on Apr 4, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



the reason it goes to the else even when it is empty is because you are testing for null, empty is not equal to null.

I would change your test to this

if(empty [php.net]($category_query))

that will test for different empty type values

Returns FALSE if var has a non-empty and non-zero value.

The following things are considered to be empty:

"" (an empty string)
0 (0 as an integer)
"0" (0 as a string)
NULL
FALSE
array() (an empty array)
var $var; (a variable declared, but without a value in a class)