Page 1 of 1

won't display all images

Posted: Fri Jan 02, 2004 7:41 pm
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]

Posted: Fri Jan 02, 2004 7:51 pm
by d3ad1ysp0rk
please put your code in [ php] [ /php] tags

Posted: Fri Jan 02, 2004 8:58 pm
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"