won't display all images

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
bluesman333
Forum Commoner
Posts: 52
Joined: Wed Dec 31, 2003 9:47 am

won't display all images

Post by bluesman333 »

I'm having trouble displaying all the images in the query. Can anyone tell me why this might be happening.

Code: Select all

$result = mysql_query("SELECT * FROM models");
$num_rows = mysql_num_rows($result);
print $num_rows;
$z = $num_rows / 4;
$x = 0;
$y = 0;
while($col=mysql_fetch_array($result)) {
$name[] = $col['Name'];
$images[]=$col['imagepath'];
$celldata[]="\n\t<td align="center"><input name="images[]" type="checkbox" value="$col[imagepath]">Lightbox</td>";
}
print "<html>\n<title>some site</title>\n<head></head>\n<body>";
print "\n<table align="center" bgcolor="white" border="1">";
while ($x < $z) {
print "\n<tr>";
$slice = array_slice($images, $y, 4);
$rowslice = array_slice($celldata, $y, 4);
$nameslice = array_slice($name, $y, 4);

foreach ($slice as $pix) {
print "\n\t<td><img src="/models/thumbnails/$pix"></td>";
}

print "\n</tr>";

foreach ($nameslice as $imgname) {
print "<td>$imgname</td>";
}

print "\n</tr>";

foreach ($rowslice as $newrow) {
print $newrow;
}

$x++;
$y+=5;
}

print "\n</table>\n</body></html>";
?>
[Edit: Added PHP tags for eyecandy. --JAM]
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

please put your code in [ php] [ /php] tags
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post by redmonkey »

$y+=5;

Should be....

$y+=4;

Arrays start at zero so given the following array.....

$input = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j");

you get the following......

$output = array_slice($input, 0, 4); // returns "a", "b", "c" and "d"
$output = array_slice($input, 5, 4); // returns "f", "g", "h" and "i"
Post Reply