I have an html table with rowspan same like in the html code:
<table class="" id="mergeTbl" border='1'>
<tbody>
<tr >
<td align="center" style="width:100px">A</td>
<td align="center" style="width:100px">1</td>
<td align="center" style="width:100px">12.01 Ct</td>
<td align="center" style="width:100px">3.01</td>
</tr>
<tr>
<td align="center" rowspan="3">B</td>
<td align="center">3</td>
<td align="center">13.02 Ct</td>
<td align="center">4.90</td>
</tr>
<tr>
<td align="center" rowspan="2">4</td>
<td align="center" rowspan="2">11.48 Ct</td>
<td align="center">2.70</td>
</tr><tr>
<td align="center">1.70</td>
</tr>
<tr>
<td align="center" rowspan="3">C</td>
<td align="center">5</td>
<td align="center">16.75 Ct</td>
<td align="center">5.35</td></tr><tr>
<td align="center">6</td>
<td align="center">14.09 Ct</td>
<td align="center">5.01</td></tr>
<tr><td align="center">7</td>
<td align="center">11.35 Ct</td>
<td align="center">4.01</td>
</tr>
</tbody></table>
Output:
I want to color with alternate row background color. Like:
Each row is in a loop such as A,B and C (Main Loop).
Add This CSS
<style>
.style1{
background-color: cyan;
}
.style2{
background-color: blue;
}
</style>
HTML :
echo "<table>";
$select = "select * from table";
$query = mysql_query($select)
$i=0;
while($i < mysql_fetch_array($query))
{
if($i%2==0){
echo "<tr class='style1'>";
}
else{
echo "<tr class='style2'>";
}
echo "<td>A</td>";
echo "</tr>";
$i++;
}
echo "</table>";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.