Jump to content

Archived

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

shannonp

DW, PHP, MySQL and alternating colored rows

Recommended Posts

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

Share this post


Link to post
Share on other sites

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

 

 

Share this post


Link to post
Share on other sites

I wish it was that simple!! I want to use 2 colours with an unknown amount of rows.

 

Shannon

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

×

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.