Do not echo empty field from Mysql

NarrowVictory

https://php-forum.com/index.php?threads/do-not-ech
I have the following for not printing an empty field in the MYSQL table:

if (trim($option_second) == "") { echo ""; } else { echo "<strong>Option:</strong> $option_second"; }

I have a search page now that displays the records for the MYSQL table, but I do not know how to hide the records that are empty like the above code. Here is what I have:

Option: <?= $items['option_second']; ?>

I would like this to not print if empty like the first code.

Thank you
 
Please check MYSQL table printing code :

Code:
<?php
if (trim($items['option_second']) != "") {
echo "<strong>Option:</strong> {$items['option_second']}";
}
?>


AND change option print code :

Code:
<?= trim($items['option_second']) != "" ? "<strong>Option:</strong> {$items['option_second']}" : ""; ?>
 
You can achieve this by incorporating the same logic you have in your PHP code that handles the display of the option_second field. Here's how you can modify your PHP code to achieve that:


<?php
if (trim($items['option_second']) != "") {
echo "<strong>Option:</strong> " . $items['option_second'];
}
?>
This code checks if the option_second field is not empty before echoing it with the <strong> tag. If it's empty, nothing will be printed.
 
Back
Top