SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Oct 2008
    Location
    Derby, UK
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Probably an easy layout/PHP thumbnail question

    I have a quick question about using pictures with a PHP site. I have a table with the following fields:

    thumbnail
    original
    caption

    I also have a news section and some reports contain images and some do not. I have the pictures loading for the particular news story no problem. My news section is a specified width so at the end of each story I want a series of thumbnails at the bottom. What I want to do is have the thumbnails load, and if they get to a stage where there are more than for, a new table row is created, as at present they just go wild and overlap my content.

    So far on my page I have the following setup

    Code:
    echo '<table>';
        echo '<tr>';
        getnewsimages($newsid); <-- this calls the method for the picture with the news story id
        echo '</tr>';
        echo '</table>';

    My method then contains this code, and this creates the first line correctly, moves to the second but then creates a new row every time a thumbnail is generated:

    Code:
     while ($row = mysql_fetch_array($gallery))
        {
            $thumbnail = $row['thumbnail'];
            $original = $row['original'];
            $caption = $row['caption'];
            ++$count;
    
            if ($count <= "4")
            {
                echo '<td>';
                echo '<img src="'.$thumbnail.'">';
                echo '</td>';
                
            }
            elseif ($count > "4")
            {
                echo '<tr>';
                echo '<td>';
                echo '<img src="'.$thumbnail.'">';
                echo '</td>';
            }
    It is probably a schoolboy error but I was wondering if anyone can see the obvious mistake/omission?

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,394
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    You'll have to reset the counter once you've reached the end of a row. Btw, you'll also have to write the closing </tr> tag somewhere.
    And if $count is a counter, containing a numeric value, why do you confront it with "4"? 4 without the quotes will work just fine


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
  •