Return data field zero value 0

I save the value of the switch, which can be true, false, or NULL in the database. In the case of null or false, the answer is 0, which is false. Is there a solution to check for a null value? I tried using isset and Empty, but none of them help. The database is MSSQL, and the data type is a bit to store the value of the switch

<input name="radioVal" type="radio" id="radioVal" value="false" <?PHP if(row['radioVal'] == false ) echo "checked='checked' "; } ?> /> <input name="radioVal" type="radio" id="radioVal" value="true" <?PHP if(row['radioVal'] == true ) echo "checked='checked' "; } ?> /> 
+4
source share
3 answers

TRY

  if(false === row['radioVal'] ) //or if(NULL === row['radioVal'] ) 

and to check for NULL, you can check with is_null

  is_null(row['radioVal']) 
+1
source

The bit column is likely to be represented as 1 or 0 . Use a triple to check the value and type. Check that row['radioVal'] === 1 for true, row['radioVal'] === 0 for false and row['radioVal'] === null for null.

+1
source

Perhaps you should use a different data type in your SQL database.

I suggest Enum or something like that:

 ENUM('false', 'true', 'NULL') 

In your PHP file you

 <?PHP if(row['radioVal'] == false ) echo "checked='checked' "; } ?> 
0
source

Source: https://habr.com/ru/post/1433638/


All Articles