Skip to content
Advertisement

If database entry null, do not display div

I have a database with option1, option2, option3, option4, option5 as columns. Options 1-3 have data entered, however, options 4-5 are NULL.

How can I set it so that a div is NOT displayed if option in database is NULL?

PHP code:

JavaScript

CSS code:

JavaScript

At the moment, even for options 4-5, div class=”null” is not working and div class=”row” is being displayed (height=70px) but is blank.

Advertisement

Answer

You are comparing the actual query to null, not the individual columns.

JavaScript

The line above returns a mysqli-result object, not the rows or columns – use your $row variable in the loop, which holds each row, like this

JavaScript

See that this code compares $row['option1'] with null, instead of $result compared to null.

You can also just don’t do anything if there are no rows, since you don’t display the div at all.

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement