-3

I've come to see you for a question. Is there a condition in SQL that allows you to do that:

IF(sup = void) {
}

Database

id | name | lastname   |     city  | mail          |  number  |     picture   | ... 
 1 | kiwi |    kiwi    |   USA    | kiwi@gmail.com | 0000000000 | default.img | (vide)
Kiwi
  • 44
  • 5
  • Please add the database technology you are using. There is an IF clause and also a CASE clause, depending on what you want to achieve. Also i assume void is NULL. in that case you can use IS NULL – Gabriel Durac Apr 21 '20 at 14:06
  • 1
    I assume what you want could be achieved by "SELECT * FROM your_table WHERE sup IS NULL" – Gabriel Durac Apr 21 '20 at 14:07

1 Answers1

1
SELECT * FROM your_table WHERE sup IS NULL

https://www.w3schools.com/sql/sql_null_values.asp

Update after reading your comment.

$test = $db->query("SELECT * FROM ressource_view WHERE ID = 1")

Will give you the result of your query. Be careful as there could be multiple rows returned.

To fetch the first row

$row = $result->fetch_array()

And then to check if the sup column of your row is null you can use:

if(is_null($row['sup']))
{
}

Or this will have the same effect

if($row['sup'] === NULL)
{
}

But best to tag your question with PHP, MySQL. Your problem seems to be more on the PHP side and someone else could provide a better answer.

Gabriel Durac
  • 2,610
  • 1
  • 12
  • 13
  • So I have to do: $test = $db->query("SELECT * FROM ressource_view WHERE ID = '1' AND sup IS NULL");
    if($test) {
    echo 'The box is empty';
    }

    Sorry I'm a rookie.
    – Kiwi Apr 21 '20 at 14:25
  • That looks like PHP code so I assume you are using MySQL as the DBMS. Please tag the question with those keywords as well. Also ID is genrally numeric so you would need to do ID=1 instead of ID='1'. But you need to explain what you are trying to achieve, so I can help you. – Gabriel Durac Apr 21 '20 at 14:36
  • https://i.stack.imgur.com/a3MTZ.png -> Database image Actually, that's what I'd like to do. If for example id='5' and empty then I display this. It's to make a dynamic flowchart. Sorry I had a little trouble using stackoverflow. – Kiwi Apr 21 '20 at 15:06
  • I think what you want is parse through the results and whenever sup is null display something additional. You could read how to do that here : https://stackoverflow.com/questions/1756743/how-to-loop-through-a-mysql-result-set – Gabriel Durac Apr 21 '20 at 15:10