Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Feb 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    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

  • #3
    New to the CF scene
    Join Date
    Feb 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Mwnciau,

    I'll give it a try - thanks

  • #4
    New to the CF scene
    Join Date
    Feb 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Mwnciau,

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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •