I edited my post because the info I placed was inacurate as I misunderstood your problem and I cannot delete the post
GliderPilot
Junior Poster in Training
86 posts since Sep 2006
Reputation Points: 8
Solved Threads: 4
Okay I understand your problem now... I would have re-edited my post but it won't allow me so I will have ot double post.
You will probably have to add another if statement in there because if you do it this way, and you don't have a number of pictures that is divisable by 3 you will get broken images.
For example if you have 7 images. The first two rows will have images fine, but the third row will have one good image and two broken images.
Try something like this:
$selection = $_GET['scelta'];
$query = 'SELECT photo_code FROM'. $selection .';';
$result = mysql_query($query);
$rows_nb = mysql_num_rows($query);
$pic_num = 0; // Set a new variable for counting our pics, and set it to 0.
$pic_code = mysql_fetch_array($result); Get our array of codes.
print('<table width="75%" border="0" align="center">');
while ($row = mysql_fetch_assoc($result))
{
print('<tr>');
for ($tb_rows=0;$tb_rows<3;$tb_rows++)
{
if ($pic_num < $rows_nb) //check that we have not exceeded the number of pictures
{
print('<td><div align="center"><a href="show.php?code='. $pic_code[$pic_num] .'"><img src="imagedb/thumbs/'. $pic_code[$pic_num] .'_small.png" border="1" /></a></div></td>'); //change our row arrays to pic arrays.
$pic_num++ // Increase the number of pictures we have placed.
}
else
{
print('<td></td>');
}
}
print('</tr>');
}
print('</table>');
Changing you $row['id'] to the new $pic_code[$pic_num] should fix your problem with displaying the same pic as well.
GliderPilot
Junior Poster in Training
86 posts since Sep 2006
Reputation Points: 8
Solved Threads: 4
I know what went wrong. Each time you fetch the array it only gets the first row. So you have to put the fetch array inside the loop so it gets each row (each seperate pic info) like this:
$selection = $_GET['scelta'];
$query = 'SELECT photo_code FROM'. $selection .';';
$result = mysql_query($query);
$rows_nb = mysql_num_rows($result);
$pic_num = 0; // Set a new variable for counting our pics, and set it to 0.
print('<table width="75%" border="0" align="center">');
while ($row = mysql_fetch_assoc($result))
{
print('<tr>');
for ($tb_rows=0;$tb_rows<3;$tb_rows++)
{
$pic_code = mysql_fetch_array($result); //Get our code array for current pic
if ($pic_num <= $rows_nb) //check that we have not exceeded the number of pictures
{
print('<td><div align="center"><a href="show.php?code='. $pic_code[0] .'"><img src="imagedb/thumbs/'. $pic_code[0] .'_small.png" border="1" /></a></div></td>'); //change our row arrays to pic arrays.
$pic_num++ // Increase the number of pictures we have placed.
}
else
{
print('<td></td>');
}
}
print('</tr>');
}
print('</table>');
I alos fixed a couple small errors in the code that I missed before. Sorry I wrote it a little quickly and made a couple dumb mistakes. But the code above should work.
GliderPilot
Junior Poster in Training
86 posts since Sep 2006
Reputation Points: 8
Solved Threads: 4
This is how phpBB 3 gets images. Maybe it'll help you out.
/**
* Get user avatar
*
* @param string $avatar Users assigned avatar name
* @param int $avatar_type Type of avatar
* @param string $avatar_width Width of users avatar
* @param string $avatar_height Height of users avatar
* @param string $alt Optional language string for alt tag within image, can be a language key or text
*
* @return string Avatar image
*/
function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $alt = 'USER_AVATAR')
{
global $user, $config, $phpbb_root_path, $phpEx;
if (empty($avatar) || !$avatar_type)
{
return '';
}
$avatar_img = '';
switch ($avatar_type)
{
case AVATAR_UPLOAD:
$avatar_img = $phpbb_root_path . "download/file.$phpEx?avatar=";
break;
case AVATAR_GALLERY:
$avatar_img = $phpbb_root_path . $config['avatar_gallery_path'] . '/';
break;
}
$avatar_img .= $avatar;
return '<img src="' . $avatar_img . '" width="' . $avatar_width . '" height="' . $avatar_height . '" alt="' . ((!empty($user->lang[$alt])) ? $user->lang[$alt] : $alt) . '" />';
}
SRC: phpBB3.0.0 includes/functions_display.php
Suetan
Junior Poster in Training
76 posts since Feb 2008
Reputation Points: 11
Solved Threads: 5
Try this:
<?php
$i = 0;
$image_id = '';
$image_path = '';
$td = 0;
echo('<tr>');
while($i <= 10)
{
$sql = "SELECT * FROM ' . IMAGES_TABLE . '
WHERE image_id = $image_id
AND image_path = $image_path";
while($td <=3)
{
echo('<td><img src="');
echo($image_path);
echo('"></td>');
$td++;
if($td == 3)
{
echo('</tr><tr>');
$td = 0;
}
}
$i++;
echo('</tr>');
}
I hope that's going to help some.
Posted a second time because the system wouldn't let me post my edits.
Basicly all I did was take what phpBB3 does and simplify it for displaying multiple images.
Suetan
Junior Poster in Training
76 posts since Feb 2008
Reputation Points: 11
Solved Threads: 5