Jump to content

arranging images to fill all available space


plugnz

Recommended Posts

Hi there,

 

I am trying to display images from a database selected and want the images to fill the page horizontally rather than vertically. The code I have got so far kind of gets there but I get the top row repeating the same image. Code is as follows:

$ImageDir = "img/category/";
$ImageThumb = $ImageDir . "thumbnails/";
  
  $getpic = "SELECT image_id, image_group, image_name, location_no " .
               "FROM cms_images_category " .
		   "WHERE category_name = '" . $_GET['category'] . "'";
               "ORDER BY image_group ";
		   
      $results = mysql_query($getpic,$conn)
        or die(mysql_error());

    while ($row = mysql_fetch_array($results)) {
  extract($row);
$images = $ImageThumb . $image_id . ".jpg";

$i = 0;
//echo "<table> \n";
for ($y=1;$y<=2;$y++) {
   echo "<tr> \n";
   for ($x=1;$x<=3;$x++) {
	echo "<td><h2>" . $image_group . "</h2></td>\n";
	echo "<td><a href =\"".$ImageDir . $image_id . ".jpg\" target='top'>"; 
    echo "<img src=\"".$images[$i++] . "\"></a></td>\n";
	echo "<td><h2>" . $image_name . "</h2></td>\n";
   }
   echo"</tr> \n";
}	 
} 

 

As soon as I try to add [$i++] after the $images the images disappear. take it out and get my images back but repeated three times on each row...

 

What am I doing wrong here?

Ok, here it is again but just the bit pertaining to the for loop


    while ($row = mysql_fetch_array($results)) {
  extract($row);
$images = $ImageThumb . $image_id . ".jpg";

$i = 0;
//echo "<table> \n";
for ($y=1;$y<=1;$y++) {
   echo "<tr> \n";
   for ($x=1;$x<=3;$x++) {
	echo "<td><h2>" . $image_group . "</h2></td>\n";
	echo "<td><a href =\"".$ImageDir . $image_id . ".jpg\" target='top'>"; 
    echo "<img src=\"".$images[$i++] . "\"></a></td>\n";
	echo "<td><h2>" . $image_name . "</h2></td>\n";
   }
   echo"</tr> \n";
}	 
} 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.