shannonp Posted April 16, 2004 Share Posted April 16, 2004 Hi all, I've been trying to do alternating coloured rows with DW, PHP and Mysql. I've tried following the tutorial on this site plus a few other sthat I've come across but none seem to be working. I gather it has something to do with the fact that DW does a '<?php do {' statement followed by the table info finally follwed by the 'while' statement to perform a repeating region. I have tried various combinations of code but still nothing....can anyone help? I have included the code for the table just in case: <snip> <table border="1"> <tr> <td>fieldtitle1</td> <td>fieldtitle2</td> </tr> <?php do { ?> <tr> <td><?php echo $row_comp['fieldresult1']; ?></td> <td><?php echo $row_comp['fieldresult2']; ?></td> </tr> <?php } while ($row_comp = mysql_fetch_assoc($comp)); ?> </table> </snip> Cheers, Shannon Quote Link to comment https://forums.phpfreaks.com/topic/1794-dw-php-mysql-and-alternating-colored-rows/ Share on other sites More sharing options...
homchz Posted April 16, 2004 Share Posted April 16, 2004 Would it not be easier to use CSS for this then build what you need in PHP around that? How many colors? As I do not use CSS but.. I just put the colors in the backround of the table I want then use a repeating region for the table to repeat the look. I use it with images in tables and text here. http://www.joshua-jones.com Quote Link to comment https://forums.phpfreaks.com/topic/1794-dw-php-mysql-and-alternating-colored-rows/#findComment-5878 Share on other sites More sharing options...
shannonp Posted April 16, 2004 Author Share Posted April 16, 2004 I wish it was that simple!! I want to use 2 colours with an unknown amount of rows. Shannon Quote Link to comment https://forums.phpfreaks.com/topic/1794-dw-php-mysql-and-alternating-colored-rows/#findComment-5879 Share on other sites More sharing options...
shannonp Posted April 16, 2004 Author Share Posted April 16, 2004 I decided to give it another go and I worked it out. For everyone out there who is interested in the code, here it is: <snip> <?php $color1 = "#FFFF99"; $color2 = "#FFFFFF"; $row_count = 0; ?> <table border="1"> <tr> <td>fieldtitle1</td> <td>fieldtitle2</td> </tr> <?php do { ?> <tr> <?php $row_color = ($row_count % 2) ? $color1 : $color2; { $row_count++; }?> <td bgcolor="<?php echo $row_color; ?>"><?php echo $row_comp['fieldresult1']; ?> </td> <td bgcolor="<?php echo $row_color; ?>"><?php echo $row_comp['fieldresult2']; ?></td> </tr> <?php } while ($row_comp = mysql_fetch_assoc($comp)); ?> </table> </snip> As you can see, the code is (almost) identicle to whats in the tutorial on this site ( http://www.phpfreaks.com/tutorials/5/0.php ) except that I have modified it to fit in with the DW coding. Shannon Quote Link to comment https://forums.phpfreaks.com/topic/1794-dw-php-mysql-and-alternating-colored-rows/#findComment-5881 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.