Re: Create a matrix gallery

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Humani Power wrote:
hi list. I wonder if anyone can help me with this.
i have a database with the file name of several images stored in a
filesystem, and I want to create a table containing the image results of a
query.

this is my code

<snip>
     while ($rows=mysql_fetch_assoc($getpic))
     {
      extract ($rows);
      echo "<tr>";
     echo "<td><a href=editing_image.php?pic=".$rows['image_id']."><img
src=".$ImageThumb.$rows['image_id'].".jpg></td>";
       }
<snip>
With this code, I am able to see the thumb images with their respective link
ok, but if I have a query with 40 results, I will have a big row of images.
____________________________________________________

|pic1 | pic2 | pic3 | pic4 | pic5 | pic6 | pic7 | pic8 | pic9 | pic10 |
______________________________________________________


What I want to to do is insert a new <td> after showing 5 thumb images, and
continue with the next picture on the next row.
something like this
__________________________
|pic1 | pic2 | pic3 | pic4 | pic5 |
__________________________
|pic6 | pic7 | pic8 | pic9 | pic10 |
__________________________
|pic11 | pic12 | pic13 |
__________________

This is really quite simple...

$col = 1;
while ($rows=mysql_fetch_assoc($getpic))
{
    extract ($rows);
    if ($col == 1) echo "<tr>";
echo "<td><a href=editing_image.php?pic=".$rows['image_id']."><img src=".$ImageThumb.$rows['image_id'].".jpg></td>";
    if ($col++ == 5)
    {
        echo "</tr>";
        $col = 1;
    }
}

Not sure why you are using extract when you then go on to use $rows as an array. Also, you're lacking quotes around the href in the link you output, and also the src in the image. It's also missing a closing </a> tag. And you should be using urlencode when putting values into a URL. And while I'm at it, $row is more semantically correct than $rows.

Try this...

$col = 1;
while ($row = mysql_fetch_assoc($getpic))
{
    if ($col == 1) echo '<tr>';
    $image_id = urlencode($row['image_id']);
echo '<td><a href="editing_image.php?pic='.urlencode($image_id).'"><img src="'.$ImageThumb.urlencode($image_id).'.jpg" /></a></td>';
    if ($col++ == 5)
    {
        echo '</tr>';
        $col = 1;
    }
}

-Stut

--
http://stut.net/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux