echoCarlos Posted May 30, 2011 Share Posted May 30, 2011 Hey guys. I've made a script which will allow people to buy items, when an item is sold it will delete from the database. so its easy to see the items i have it have separate colors so its dark grey and light grey on the next line and so on. But the problem is when the item is bought 2 of the same colors are next to each other. I am checking if the item_id is an odd or even number to get the result I want but cant figure out a soluction to when an item is purchased. <?php foreach(getItems() as $item): ?> <?php if($item['item_id'] & 1): ?> <tr class="grey2"> <?php else: ?> <tr class="grey"> <?php endif; ?> <td><?php echo $item['item_account']; ?></td> <td><?php echo $item['item_country']; ?></td> <td><?php echo $item['item_info']; ?></td> <td><?php echo $item['item_login']; ?></td> <td><?php echo $item['item_pass']; ?></td> <td><?php echo $item['item_price']; ?> </td> <td><form method="post" action="#"><input type="submit" name="buy" value="Buy" class="button" /></form></td> </tr> <?php endforeach; ?> Thanks guys Link to comment https://forums.phpfreaks.com/topic/237905-help-with-different-colours-per-line-for-shopping-cart-type-script/ Share on other sites More sharing options...
jcbones Posted May 30, 2011 Share Posted May 30, 2011 $class = 'grey'; <?php foreach(getItems() as $item): ?> <?php $class = ($class == 'grey') ? 'grey2' : 'grey'; ?> <tr class="<?php echo $class; ?>"> <td><?php echo $item['item_account']; ?></td> <td><?php echo $item['item_country']; ?></td> <td><?php echo $item['item_info']; ?></td> <td><?php echo $item['item_login']; ?></td> <td><?php echo $item['item_pass']; ?></td> <td><?php echo $item['item_price']; ?> </td> <td><form method="post" action="#"><input type="submit" name="buy" value="Buy" class="button" /></form></td> </tr> <?php endforeach; ?> I think that's right. Link to comment https://forums.phpfreaks.com/topic/237905-help-with-different-colours-per-line-for-shopping-cart-type-script/#findComment-1222523 Share on other sites More sharing options...
seanlim Posted May 30, 2011 Share Posted May 30, 2011 Edit: oh wait, just realised your key isn't in consecutive order. Anw, you can also achieve that using css and the :nth-child(odd) selector Link to comment https://forums.phpfreaks.com/topic/237905-help-with-different-colours-per-line-for-shopping-cart-type-script/#findComment-1222525 Share on other sites More sharing options...
echoCarlos Posted May 30, 2011 Author Share Posted May 30, 2011 thanks for the reply guys will try those edit: thanks jcbones your way works perfectly Link to comment https://forums.phpfreaks.com/topic/237905-help-with-different-colours-per-line-for-shopping-cart-type-script/#findComment-1222534 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.