Jump to content
Pardon our ads (a necessary update) ×

Display text if a database field is null else display another text


zazu

Recommended Posts

Hi guys,

 

I've a little problem i have a fileld in my database that i want to check. If is null to display some text else display another text. I've manage to do something like this but doesn't work. The code is below:

                    <?php
$result = @$mysqli->query("SELECT * FROM depanarecuora_clients WHERE paid_status = '$paid_status'");
while ($result = mysqli_fetch_assoc($result))
  if (is_null($paid_status)) {
  echo "some text";
} 
            ?>

The whole piece of code is wrong.

 

First, do not use the @ to suppress errors. Errors are your friend. They tell you something is wrong and what the problem is.

 

If you just want the state of one column, just select that one column, not selecting everything with *.

 

By adding the WHERE condition you are specifying a certain status to return so you will not get all the status's of that column.

 

Then you are checking your user supplied value of $paid_status for null instead of the database column status.

 

Additionally, the query could be done with a MySQL IF

http://www.w3resource.com/mysql/control-flow-functions/if-function.php

 

SELECT 
IF(paid_status IS NULL,'Status is null','Status is not null') AS "paid_status"  
FROM depanarecuora_clients;  

Archived

This topic is now archived and is closed to further replies.



×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.