Jump to content

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

Link to comment
https://forums.phpfreaks.com/topic/1794-dw-php-mysql-and-alternating-colored-rows/
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

 

 

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

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.