Jump to content

help with different colours per line for shopping cart type script


echoCarlos

Recommended Posts

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

$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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.