View Full Version : Alternate Row colours

08-10-2012, 10:34 PM
Hi Everyone, just wondering if anyone may be able to help.

Sorry if this is the wrong section.

I am not a fluent coder and have built a website for work in PHP using phpmyadmin. I usually do what I need in dreamweaver 4 and then study the code after to see how it is made up.:grin:

I have included a dynamic table and am needing to set alternate rows colours. I have trawled the web and not found anything either for what I need or that I understand. :( Is there a simple way in dreamweaver cs4 to do this.

I found this http://www.dreamweaverclub.com/forum/showthread.php?t=27272&highlight=alternate+row but it didn't seem to work for me. :confused:

Super grateful of your help:grin:


08-11-2012, 12:51 AM
it should. do you mean its not because you used dreamweaver to create record sets?

08-11-2012, 01:02 AM
try this. edit the connections to your own, I used as DW for this
edit table and field names

<?php require_once('Connections/???.php'); mysql_select_db($database_???, $????);

$sql = "SELECT * FROM `table` ORDER BY field1 DESC Limit 15";
$result = mysql_query($sql);
$row= mysql_fetch_array($result);

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>alternate rows/title>
.color2{background-color:#999; color:#FFF;}
td a{color: #C03; font-weight:bold;}



$no = 1;

do {
$divide = $no / 2;
$detect = strstr($divide,'.');

//check the IF statement in <tr> to echo the appropriate class
//if $detect is true then that is odd so echo color1 else echo color2

<tr <?php if($detect){echo "class=\"color1\"";}else{echo "class=\"color2\"";} ?>>
<td><?php echo "Ref ". $row['field1'];?></td>

<td><?php echo $row['field2']?></td>
<td><?php echo $row['field3']?></td>
<td> <?php echo $row['field4']?></td>

$no++; //<< increment count.
}while ($row = mysql_fetch_array($result))

08-13-2012, 09:54 AM
Thanks, i'll give this a try. I did make the record set in DW. I used the GUI rather then coded it though.