Simple Question by PHP

1

I have this variable extracted from MySQL, what I want is that if NOT NULL is seen in PHP but if it is NULL, no result in PhP is seen, is this possible?

<? echo ''.$result21['Nombre_Esp'].'' ?>

If it is positive how should I place the result if Name_Esp is not available

    
asked by Juan Carlos Villamizar Alvarez 26.11.2018 в 19:44
source

3 answers

3

Try this way:

        <?php


            if(!is_null($result21['Nombre_Esp'])){
                echo $result21['Nombre_Esp'];
            } 

        }

Quick example:

    
answered by 26.11.2018 / 19:46
source
0

The advisable thing would be to carry out previous verifications, first if the variable exists (that could be the case) and then if it is or not null.

You could do something like this:

if(isset($result21['Nombre_Esp'])) // Si está definida y no es null
{
        echo $result21['Nombre_Esp'];
}
else
{
        echo ' No existe la varible o es null';
}

The use of! is_null just in case I think it falls short.

    
answered by 26.11.2018 в 20:05
0

Since you know that the variable exists, because it is part of the answer of your query, it is not necessary to use any additional function, you can directly ask for the variable, and in case it is true imprimís:

<?php if($result21['Nombre_Esp']) echo $result21['Nombre_Esp']; ?>
    
answered by 26.11.2018 в 21:39