Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-31-2006, 12:46 AM   PM User | #1
DragonI
New to the CF scene

 
Join Date: Feb 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
DragonI is an unknown quantity at this point
HTML gallery layout logic help

Hi,

Sorry, my brain is dead . 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;

Last edited by DragonI; 08-31-2006 at 02:01 AM..
DragonI is offline   Reply With Quote
Old 08-31-2006, 01:13 AM   PM User | #2
Mwnciau
Regular Coder

 
Join Date: May 2006
Location: Wales
Posts: 820
Thanks: 1
Thanked 82 Times in 79 Posts
Mwnciau is on a distinguished road
Hmmm, heres some code from a previous page I made... You should be able to configure it to your needs...:

PHP Code:
$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
Mwnciau is offline   Reply With Quote
Old 08-31-2006, 01:27 AM   PM User | #3
DragonI
New to the CF scene

 
Join Date: Feb 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
DragonI is an unknown quantity at this point
Thanks Mwnciau,

I'll give it a try - thanks
DragonI is offline   Reply With Quote
Old 09-07-2006, 05:32 AM   PM User | #4
DragonI
New to the CF scene

 
Join Date: Feb 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
DragonI is an unknown quantity at this point
Hi Mwnciau,

Just wanted to say thanks for your help. Your code worked like a charm
DragonI is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:48 PM.


Advertisement
Log in to turn off these ads.