SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Enthusiast Red Blaze's Avatar
    Join Date
    Feb 2006
    Location
    Texas
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    # of items per table row.

    I want PHP to organize a certain number of items in a row of a table and jump to the next row.

    This is my table:
    Code:
    <?php do { ?>
      <table cellspacing="0" cellpadding="0">
        <tr>
          <td><a href="<?php echo $images_dir ?>/<?php echo $row_call_photos['photo_filename']; ?>" target="_blank"><img src="<?php echo $images_dir ?>/tb_<?php echo $row_call_photos['photo_filename']; ?>" border="0" /></a></td>
        </tr>
      </table>
      <?php } while ($row_call_photos = mysql_fetch_assoc($call_photos)); ?>
    Help and leads will be greatly appreciated.

  2. #2
    SitePoint Evangelist ClickHeRe's Avatar
    Join Date
    Mar 2005
    Location
    Ottawa, Canada
    Posts
    580
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Something along these lines, think you get the idea. Change the 5 value everywhere to the number of columns.

    PHP Code:

    <?php 

    $i 
    0;
    do { 

    ?>
      <table cellspacing="0" cellpadding="0">
        <?php if ( $i == ) echo '<tr>'?>
          <td><a href="<?php echo $images_dir ?>/<?php echo $row_call_photos['photo_filename']; ?>" target="_blank"><img src="<?php echo $images_dir ?>/tb_<?php echo $row_call_photos['photo_filename']; ?>" border="0" /></a></td>
       <?php if ( $i == ) echo '</tr>'?>
      </table>
    <?php 
      
    ++$i;
    } while (
    $row_call_photos mysql_fetch_assoc($call_photos));

      if ( 
    $i != ) echo '</tr>';
    ?>
    David

  3. #3
    does not play well with others frezno's Avatar
    Join Date
    Jan 2003
    Location
    Munich, Germany
    Posts
    1,391
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how about something like:
    PHP Code:
    <table cellpadding="5" width="100%" summary="">
    <tr>
    <?php
        
    //-- Howm many images per line should be displayed?
        
    $photos_per_line 5;
     
        
    //-- Set start counter for displaying the images per line
        
    $i=1;
     
        
    //-- fetch image info from the database
        
    while ($img mysql_fetch_array($sql))
        {
            print 
    '<td><a href="./images.php?id='$img['photo_id'] .'">';
            print 
    '<img src="'$imgages_dir .'" border="0" alt="'$img['photo_filename'] .'"><br><br>';
        }
     
        print 
    $img['photo_filename'] .'</a><br></td>';
     
        
    //-- Check qty of displayed images and include a line break after defined quantity.
        
    if (!($i $photos_per_line))
        {
            print 
    '</tr><tr>';
        }
     
        
    //-- increment counter
        
    $i++;
    ?>
    </tr>
    </table>
    We are the Borg. Resistance is futile. Prepare to be assimilated.
    I'm Pentium of Borg.Division is futile.Prepare to be approximated.


Bookmarks

Posting Permissions

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