Using css to alternate dynamic table row colors

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ibiangalex

    Using css to alternate dynamic table row colors

    I have a problem with alternating the rows of my php dynamic table. I saw an example here which I was able to use but I dont understand how to switch between between html and the php on the <tr class= <?php "' . $class .'" ?>' altrow is my css class definition. below is my mark up:

    Code:
    <tr>
    	<th scope="col">Trackid</th>
       	<th scope="col">NMEA</th>
      	<th scope="col">Date</th>
      	
    </tr>
        $result = mysql_query($sql, $link);
        $i = 0;
        if (!$result) {
            die("Query to show averages from table failed");
        }
        while ($row = mysql_fetch_assoc($result)){
        	$class = ($i++ % 2) ? 'altrow' : '';
    ?>
    	<tr class= <?php "' . $class .'" ?>>';
        <td><?php echo $row['Trackid']; ?></td>
      	<td><?php echo $row['NMEA']; ?></td>
      	<td><?php echo $row['Date']; ?></td>
      	
    </tr>
    <?php } ?>
    </table>
    Can someone please show how to achieve this alternation? Thanks
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    you have the alteration on line 14, you only need to echo it.

    Comment

    Working...