how to change table cell color depending on values in php -
i started programming in php. want change cell color depending on values. example if quantity < 1000 should display red color. don't understand how it. please me. code. have tried far. please let me know wrong , needs done. thanx in advance
<div class="c-content-panel"> <div class="c-label">basic example</div> <div class="c-body"> <div class="row"> <div class="col-md-12"> <table class="table"> <caption>optional table caption. </caption> <thead> <tr> <th>#</th> <th>store id</th> <th>item name</th> <th>quantity</th> <th>status</th> </tr> </thead> <tbody> <?php while ($row =mysqli_fetch_array($query)) { echo " <tr> <td>--</td> <td>{$row['store_id']} </td> <td>{$row['store_name']}</td> <td>{$row['quantity']}</td> if($row['quantity']<1000) { echo "<td style='background-color: #ff0000;'></td>" } else { echo "< td style='background-color: #ffff00;'></td>" } </tr>"; echo " <tr> <td>--</td> <td>{$row['store_id']}</td> <td>{$row['mphone']}</td> <td>{$row['quantity_mphone']}</td> </tr>"; echo " <tr> <td>--</td> <td>{$row['store_id']}</td> <td>{$row['smart_devices']}</td> <td> {$row['quantity_smart_devices']}</td> </tr>"; echo " <tr> <td>--</td> <td>{$row['store_id']}</td> <td>{$row['power']}</td> <td>{$row['quantity_power']}</td> </tr>"; echo " <tr> <td>--</td> <td>{$row['store_id']}</td> <td>{$row['audio']}</td> <td>{$row['quantity_audio']}</td> </tr>";} ?> </tbody> </table> </div> </div> </div> </div>
you can't write if in echo. have terminate echo before using if
<div class="c-content-panel"> <div class="c-label">basic example</div> <div class="c-body"> <div class="row"> <div class="col-md-12"> <table class="table"> <caption>optional table caption. </caption> <thead> <tr> <th>#</th> <th>store id</th> <th>item name</th> <th>quantity</th> <th>status</th> </tr> </thead> <tbody> <?php while ($row =mysqli_fetch_array($query)) { echo " <tr> <td>--</td> <td>{$row['store_id']} </td> <td>{$row['store_name']}</td> <td>{$row['quantity']}</td>"; if($row['quantity']<1000) { echo "<td style='background-color: #ff0000;'></td>"; } else { echo "< td style='background-color: #ffff00;'></td>"; } echo "</tr>"; echo " <tr> <td>--</td> <td>{$row['store_id']}</td> <td>{$row['mphone']}</td> <td>{$row['quantity_mphone']}</td> </tr>"; echo " <tr> <td>--</td> <td>{$row['store_id']}</td> <td>{$row['smart_devices']}</td> <td> {$row['quantity_smart_devices']}</td> </tr>"; echo " <tr> <td>--</td> <td>{$row['store_id']}</td> <td>{$row['power']}</td> <td>{$row['quantity_power']}</td> </tr>"; echo " <tr> <td>--</td> <td>{$row['store_id']}</td> <td>{$row['audio']}</td> <td>{$row['quantity_audio']}</td> </tr>";} ?> </tbody> </table> </div> </div> </div> </div>
Comments
Post a Comment