php

Generating a table in php with corresponding cells

A design I was working on used titles above an image in the feature area. The height of the titles needed to be consistent so they would line up.

This is is a trick for iterating cells as a unit so the titles are in a cell above an image. Complicated algorithms are avoided. In this example, the content is stored in two arrays: $tittles and $products.

$c=0;
$cc=0;
$total=count($products);
 
for ($c =0; $c <= $total; $c=$c+4) {
 
    echo
    "<tr>".    
    "<th>".$titles[$c]."</th>\n".
    "<th>".$titles[$c+1]."</th>\n".
    "<th>".$titles[$c+2]."</th>\n".
    "<th>".$titles[$c+3]."</th>\n".
    "</tr>";
 
    echo
    "\n\n".
    "<tr class='image_row'>\n".
    "<td>".$products[$cc]."</td>\n".
    "<td>".$products[$cc+1]."</td>\n".
    "<td>".$products[$cc+2]."</td>\n".
    "<td>".$products[$cc+3]."</td>".
    "</tr>\n";
 
    $cc=$cc+4;        
 
}

Leave a Reply

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

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.