I know its fairly straight-forward to create a simple HTML table with data filled-in using PHP and a database, but how do you create a HTML table so that its style can be modified using CSS and still being able to be filled-in with PHP?
Any help and/or code would be greatly appreciated. Thanks.
PHP and CSS Compatible Table
Moderator: General Moderators
Re: PHP and CSS Compatible Table
Easy:
Please be more specific where you are having problems.
Code: Select all
<style type="text/css">
table { border: 1px solid black; }
table td { background: #fff; }
table .odd td { background: #f9f9f9; }
</style>
<table>
<?php foreach($data as $k => $row) { ?>
<tr class="<?php echo ($k % 2 ? 'odd' : 'even'); ?>">
<td><?php echo $row['a']; ?></td>
<td><?php echo $row['b']; ?></td>
</tr>
<?php } ?>
</table>