Jump to content

changing every other row bg color in while loop.


seany123

Recommended Posts

i dont know if this is strictly a php problem, anyway... i have a query which returns rows from my database and then displays them in a table.. but what i want to know is how do i then get the bg color to change?

 

<?php
if ($_GET['quantity'] == null)
    {
        $_GET['quantity'] = 20;
    }
	if (mysql_numrows($gold) != 0) {
?>
    	<table width="100%">
       		<tr>
            	<td>Seller</td>
                <td>Sellers Average Delivery Speed</td>
                <td>Price (per <?=$_GET['quantity'];?>M)</td>
                <td></td>
            </tr>
    <?php
	while ($row = mysql_fetch_array($gold)) {

	$seller_id = $row['seller_id'];
	$price_unit = $row['price_unit'];
	$order_id = $row['id'];

	$user = mysql_query("SELECT * FROM users WHERE id='$seller_id'");
	$user = mysql_fetch_array($user);

	$average_time = ($user['transcation_time'] / $user['transaction_amount']);
?>        
        <tr>
	<td><center><a href="profile.php?id=<?=$seller_id;?>"><?= $user['username']; ?></a></center></td>
	<td><center><?php if ($user['transcation_amount'] <= 4){echo "Now Timing";} if ($user['transcation_amount'] >= 5){ echo $average_time; }?></center></td>		
	<td><center>$<?= $price_unit; ?></center></td>
	<td><center><a href="offer/checkout.php?order_id=<?=$order_id;?>"><img src="image/buttons/checkout.gif" width="120" height="20"></a>
	</center></td>
</tr>
    <?php	
	}
}
?>
    </table>

 

Link to comment
Share on other sites

$counter = 0;

echo "<table>"
do {

$bgclass = ($counter % 2 == 0) ? 'color1' : 'color2';

//echo row and set the class equal to $bgclass
echo "<tr class='$bgclass'><td>" . $row['databasefield'] . "</td></tr>";
$counter++;
} while ($row = mysql_fetch_assoc());

echo "</table>";

Something like that maybe?

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.