Dynamic striped table using php

by Sam  


The code below will dynamically create a table, with rows and column, using PHP.

PHP Code


<?php

$row = 5;
$col = 5;

echo '<table class="table">';
for($x=1; $x <= $row; $x++){
$class = ($x%2==0) ? 'even' : 'odd';
echo '<tr class="'.$class.'">';
for($y=1; $y <= $col; $y++){
echo '<td>row '. $x . ' , col ' . $y .'</td>';
}
echo '</tr>';
}
echo '</table>';
?>

CSS Style


<style type="text/css">
.table tr td{
padding: 10px;
}
.table tr.odd{
background: #f0f0f0;
}
</style>


Leave a Reply

Your email address will not be published. Required fields are marked *


Need of a Website?

Maybe you're planning to build a landing page for your website. You might also have a plan to create a web application. I can offer you with an affordable but with good quality services. Don't hesitate to submit your specifications by clicking the button below.

Get Quote