I have created a table using information from my database which all works fine. I have this all echo'd back in position how i want it.
My question is when i add a background to this, it adds a background to everything in every row. How can i add a background to each row with maybe 10px padding in between each background?
echo "
<table id=\"messageboard\" cellpadding=\"0\" cellspacing=\"0\">
";
echo "<tr><th width=\"150px\" style=\"text-align: center;\"></th>
";
echo "<th width=\"330px\" style=\"background-color: #c01718;\"></th>
";
echo "</tr>";;
while($row = mysql_fetch_array($result)){
echo "<tr><td>
";
echo $row ['username']."<br />".$row ['date_time'];
echo "<td>
";
echo $row ['message'];
echo "</td></tr>
";
}
You need to add the css class to the tr in order to give a style for every row
The starting row line should read
echo "<tr class=\"styledRow\"><td>
";
Check this out:
your problem can be solved by to ways:
alternatively
$style = ['style1','style2']
$i = 0
while($row = mysql_fetch_array($result))
{
if {$i ==0{$i = 1}}
else {$i = 0}
echo "<tr";
echo "class=$style[$i]";
echo "><td>
";
echo $row ['username']."<br />".$row ['date_time'];
echo "<td>
";
echo $row ['message'];
echo "</td></tr>
";
}
now in css define two style sheet style1 and style2, your table row will have alternating style as style1 and style2,
please ignore syntax error