LoRz

Saturday, June 14, 2008

 

Code to create a thumbnail like table in PHP

Code to create a thumbnail like table in PHP

$colsPerRow = columns to be displayed per row
$contents = usually array or result of a SQL query


<?php
print '<table width="90%" border="0" cellpadding="5" cellspacing="0" align="center">';

$colsPerRow = 6;
$colWidth = (int)(100/$colsPerRow);
$counter = 0;

foreach ($contents as $content)
{
if ($counter % $colsPerRow == 0)
{
print '<tr>';
}

print '<td valign="top" align="center" width="' . $colWidth . '%">$content</td>';

if ($counter % $colsPerRow == $colsPerRow - 1)
{
print '</tr>';
}

$counter += 1;
}

if ($counter % $colsPerRow != 0)
{
while ($counter++ % $colsPerRow != 0)
{
print '<td width="' . $colWidth . '%"> </td>';
}

print '</tr>';
}

print '</table>';
?>





<< Home

Archives

June 2008   July 2008   August 2008   September 2008   October 2008   November 2008   December 2008   January 2009   February 2009   March 2009   May 2009   July 2009   September 2009   October 2009   WEC 44 live stream   UFC 106 live stream

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]