seany123 Posted April 1, 2011 Share Posted April 1, 2011 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 https://forums.phpfreaks.com/topic/232443-changing-every-other-row-bg-color-in-while-loop/ Share on other sites More sharing options...
MatthewJ Posted April 1, 2011 Share Posted April 1, 2011 $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 https://forums.phpfreaks.com/topic/232443-changing-every-other-row-bg-color-in-while-loop/#findComment-1195670 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.