Jump to content


Photo

DW, PHP, MySQL and alternating colored rows


  • Please log in to reply
3 replies to this topic

#1 shannonp

shannonp
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 16 April 2004 - 02:43 AM

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

#2 homchz

homchz
  • Members
  • PipPipPip
  • Advanced Member
  • 93 posts
  • LocationLee, New Hampshire

Posted 16 April 2004 - 03:18 AM

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



#3 shannonp

shannonp
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 16 April 2004 - 03:54 AM

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

Shannon

#4 shannonp

shannonp
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 16 April 2004 - 05:54 AM

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...torials/5/0.php ) except that I have modified it to fit in with the DW coding.

Shannon




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users