SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2008
    Posts
    190
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Hmm. How to fill a space?

    Hi,
    I have created an image gallery which needs to be in the format of showing an image with a short description under that image. However, in some cases there may not be an image and in this case it is making the gallery look irregular, as when there isn't an image the text appears higher than the text under the images. Is there a way that I could have php display a blank image if there isn't an uploaded image or can anyone see a way that I could create an extra row using this code so that the alignment is sorted out. This is my code:

    PHP Code:
    echo '<table width="460" border="0" cellspacing="1" cellpadding="2" align="center">';

    $colsPerRow 5;

        
    // width of each column in percent
        
    $colWidth   = (int)(100/$colsPerRow);
        
    $i 0;
        while (
    $row mysql_fetch_assoc($result)) {
            if (
    $i $colsPerRow == 0) {
                
    // start a new row
                
    echo '<tr>';
       }

       echo 
    '<td align="center" width="' $colWidth '%">' .
               
    '<img src="images/committee/' $row['path'] . '" border="0">' .
            
    "<strong>" $row['role'] . "</strong><br />" .
            
    $row['member'] . "<br />";

       if (
    $i $colsPerRow == $colsPerRow 1) {
          
    // end this row
          
    echo '</tr>';
       }

       
    $i += 1;
    }
    if (
    $i $colsPerRow != 0) {
       while (
    $i++ % $colsPerRow != 0) {
          echo 
    '<td width="' $colWidth '%">&nbsp;</td>';
       }
       echo 
    '</tr>';
    }

    echo 
    '</table>'
    ?> 
    Thanks
    Russ

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    if (!$row['path']) {
        
    $row['path'] = 'default.jpg';



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
  •