Add alternate color rows to a table

Hi,
in my cms has this code that creates a table of products on a shopping cart checkout page. How can it be made to apply a class “alt” to every second row it creates? (but not the header row which has class “firstrow”)
So that I can use CSS to color every second row.

I believe this is all the relevant PHP that builds the table. I can post the whole file if needed.
Thanks in advance, Mark

<div id="checkout_page_container">
<h3><?php _e('Please review your order', 'wpsc'); ?></h3>
<table class="productcart">
    <tr class="firstrow">
        <td class='firstcol'></td>
        <td><?php echo __('Product', 'wpsc'); ?>:</td>
        <td><?php echo __('Quantity', 'wpsc'); ?>:</td>
        <?php if(wpsc_uses_shipping()): ?>
            <td><?php echo __('Shipping', 'wpsc'); ?>:</td>
        <?php endif; ?>
        <td></td>
        <td class="price" style="text-align:right;padding-right:10px;"><?php echo __('Price', 'wpsc'); ?>:</td>
    </tr>
   <?php while (wpsc_have_cart_items()) : wpsc_the_cart_item(); ?>
          <?php  //this displays the confirm your order html    ?>
        
        <tr class="product_row">
            <td class="firstcol"><img src='<?php echo wpsc_cart_item_image(48,48); ?>' alt='<?php echo wpsc_cart_item_name(); ?>' title='<?php echo wpsc_cart_item_name(); ?>' /></td>
            <td class="firstcol">
            <a href='<?php echo wpsc_cart_item_url();?>'><?php echo wpsc_cart_item_name(); ?></a>
            </td>
            <td>
                <form action="<?php echo get_option('shopping_cart_url'); ?>" method="post" class="adjustform">
                    <input type="text" name="quantity" size="2" value="<?php echo wpsc_cart_item_quantity(); ?>" />
                    <input type="hidden" name="key" value="<?php echo wpsc_the_cart_item_key(); ?>" />
                    <input type="hidden" name="wpsc_update_quantity" value="true" />
                    <input type="submit" value="<?php echo __('Update', 'wpsc'); ?>" name="submit" />
                </form>
            </td>
            <?php if(wpsc_uses_shipping()): ?>
            <td><span class="pricedisplay" id='shipping_<?php echo wpsc_the_cart_item_key(); ?>'><?php echo wpsc_cart_item_shipping(); ?></span></td>
            <?php endif; ?>
            <td>
                <form action="<?php echo get_option('shopping_cart_url'); ?>" method="post" class="adjustform">
                    <input type="hidden" name="quantity" value="0" />
                    <input type="hidden" name="key" value="<?php echo wpsc_the_cart_item_key(); ?>" />
                    <input type="hidden" name="wpsc_update_quantity" value="true" />
                    <button class='remove_button' type="submit"><span><?php echo __('Remove', 'wpsc'); ?></span></button>
                </form>
            </td>
            
            <td class="price" style="text-align:right;padding-right:10px;">
                <span class="pricedisplay"><?php echo wpsc_cart_item_price(); ?></span>
            </td>
        </tr>
   <?php endwhile; ?>

This code shows how you can colour rows with alternate colours.

Replace the FOR loop with your WHILE loop.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
        <title></title>
        <style type="text/css">
            .oddRow {
                background-color: green;
            }
            .evenRow {
                background-color: blue;
            }
        </style>
    </head>
    <body>
        <table cellpadding="10">
            <?php
            $count = 0;
            for($i=0; $i < 5; $i++){
                $class = ($count++ % 2 == 0)? 'evenRow' : 'oddRow';
                echo '<tr class="'.$class.'">';
                echo '<td>cell data</td>';
                echo '</tr>';
            }
            ?>
        </table>
    </body>
</html>

It would not have been me because I don’t use WP. Can you post a link to what you read or a reference (title/author) if it was a book or something similar.

Thanks,
I got it working :slight_smile:
Funny but I was just reading stuff by you somewhere else today I think. It was about your WP table plugin?