this is something I have been doing a long time but I really don't know if this is the right path.
I'll give a basic example.
if I have a stock table, and I want the row to have a yellow background color code warning when an item reaches 2 in quantity, and to turn red when the item reaches 0 in quantity.
What I did was something like this:
- Code: Select all
<?php
$stock= new Product();
$stock->GetItems();
if($stock-data > 0){
foreach($stock->data as $st){
if($st['qty'] <= 2){
echo "<td class='bgYellow'>". $st['id']. "</td>";
echo "<td class='bgYellow'>". $st['name']. "</td>";
echo "<td class='bgYellow'>". $st['price']. "</td>";
echo "<td class='bgYellow'>". $st['qty']. "</td>";
}elseif($st['qty'] == 0){
echo "<td class='bgRed'>". $st['qty']. "</td>";
echo "<td class='bgRed'>". $st['name']. "</td>";
echo "<td class='bgRed'>". $st['price']. "</td>";
echo "<td class='bgRed'>". $st['qty']. "</td>";
}else{
echo "<td>". $st['qty']. "</td>";
echo "<td>". $st['name']. "</td>";
echo "<td>". $st['price']. "</td>";
echo "<td>". $st['qty']. "</td>";
}
}
}
?>
I have also used this method but extended a bit, like creating switches on db which is nothing more than a state which is either yes/no (or true/false), I can then present certain html elements acording to those switches states. I used that for instance to make a check box default state to checked according to what the user chose earlier.
I need your opinion on this, if this is awkward, if it should really be done in client side using javascript.
Any feedback will be appreciated.
Mike


