-Mensaje original-
De: Stut [mailto:[EMAIL PROTECTED]
Enviado el: Lunes, 03 de Septiembre de 2007 06:31 p.m.
Para: Humani Power
CC: php-general@lists.php.net
Asunto: Re: [PHP] Create a matrix gallery
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 tda 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 tda 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 'tda
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