...

View Full Version : HTML gallery layout logic help



DragonI
08-31-2006, 12:46 AM
Hi,

Sorry, my brain is dead :mad: . What I'm trying to do is output an array of info for a gallery like page. Below is the function - I've stripped it down to be bare bones.

Based on the # of records, rows and columns passed, the appropriate rows and columns should be displayed. But I running into a wall.

For example, if there are 13 records and rows is 3 and columns is 5. Then there should be 3 row of results - the last row having only 3 records.

Any help would be really appreciated. Thanks

ffunction setupGallery( $EntryList = NULL, $numberOfRows, $columnsPerRow )
{
$totalRecords = count($EntryList);
$tilesPerPage = $numberOfRows * $columnsPerRow;

if ( $totalRecords < $tilesPerPage )
{
$numberOfRows = floor( $columnsPerRow - ( $totalRecords / $columnsPerRow ) );
$numberOfColums = floor( $columnsPerRow - ( $totalRecords / $columnsPerRow ) );
$isLessThan = TRUE;
}

if ( $totalRecords <= $columnsPerRow )
{
$numberOfRows = 1;
$columnsPerRow = $totalRecords;
}

$lastColumnNumber = 0;

$html_text = '<table id="MyTable" border="0">';

// total records from db
for ( $row=0; $row < $totalRecords; $row++ )
{
// This is screwed
if ( $row >= $columnsPerRow )
{
$lastColumnNumber = (int) @floor( $row / $columnsPerRow );
} else {
$lastColumnNumber++;
}

if ( $lastColumnNumber == $columnsPerRow )
{
$html_text .= '<tr>';
}

$html_text .= '<td><table><tr>';
$html_text .= '<td><div">';

$html_text .= $EntryList[$row][0] . '</div></td>';
$html_text .= '<td valign="top" align="left">';
$html_text .= '<div>';
$html_text .= '<span>' . $EntryList[$row][1] . '</span><br />';
$html_text .= '<span>' . strtoupper( $EntryList[$row][2] ). '</span>';
$html_text .= '</div>';

$html_text .= '</td></tr></table></td>';

if ( $lastColumnNumber == $columnsPerRow )
{
$html_text .= '</tr>';
}

} // end for

$html_text .= '</table>';

return $html_text;

Mwnciau
08-31-2006, 01:13 AM
Hmmm, heres some code from a previous page I made... You should be able to configure it to your needs...:



$i = 1;
echo '<table width="500" cellspacing="15">';
while ($game = mysql_fetch_array($query)){
if ($i == 1){
$open = 1;
echo '<tr>';
}
echo '<td width="30%"><center><a href="play.php?game=' . $game[id] . '"><img src="' . $game[image] . '" width="100" height="100" /><br> ' . $game[name] . ' </a></center></td>';
if ($i == 3){
$open = 0;
echo '</tr>';
$i=0;
}
$i++;
}
if ($open == 1){
echo '</tr>';
}
echo '</table>';
}


P.S. Use the [ php ] tags

DragonI
08-31-2006, 01:27 AM
Thanks Mwnciau,

I'll give it a try - thanks:thumbsup:

DragonI
09-07-2006, 05:32 AM
Hi Mwnciau,

Just wanted to say thanks for your help. Your code worked like a charm :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum