I need to display a page with detailed information about a product. e.g.
<ul>
<li>Product: <?php echo $product['Product']['name'] ?></li>
<li>Features: <?php echo $product['Product']['Features'] ?></li>
etc. (may be 20-30 fields)
The problem is that each product may have or may not have blank fields and I only need to show not empty fields to user.
How to properly filter results to generate and show only
<li>
that contain information?
I see 3 approaches.
-
Many and many of
<?php if (!empty($product['Product']['name']) echo "<li>Product: ".$product['Product']['name']."</li>"?> - Add some kind of JS filtering (I don’t know JS so it may be impossible to achieve)
-
Add another column to DB with “li” field description
(<li>Product:)and then somehow output only not empty fields with While loop…
Try this: