Reputation: 6940
i have multiplication table and i want to modify it like follows - make first row and first column items bold and centered. If i understand correct for this i just have to use tags. Still i can't figure out how to do this, that is what i tried..
<?php
$cols = 10;
$rows = 10;
?>
Lot of html text here...
<?php
echo "<table border=\"1\">";
for ($r =1; $r < $rows; $r++){
echo('<tr>');
for ($c = 1; $c < $cols; $c++)
if ($r =1 or $c=1){
echo('<th>'.$r*$c.'</th>');
}
echo( '<td>' .$c*$r.'</td>');
echo('</tr>');
}
echo("</table>");
?>
I think i miss rather obvious solution how to do this.
Any advice would be appreciated, thanks!
Upvotes: 0
Views: 435
Reputation: 7195
You've confused assignment and comparison operators. =
is assignment operator. You need to use comparison operator (==
) in if
statement.
echo '<table border="1">';
for ($r = 1; $r <= $rows; $r++){
echo '<tr>';
for ($c = 1; $c <= $cols; $c++)
if ($r == 1 || $c == 1)
echo '<th>'. $r * $c. '</th>';
else
echo '<td>'. $r * $c. '</td>';
echo '</tr>';
}
echo '</table>';
Upvotes: 2
Reputation: 402
Use the following CSS selector
table>tr:first-child>*, table>tr>td:first-child, table>tr>th:first-child {
font-weight:bold;
text-align:center
}
Upvotes: 3