Jump to content

How to sort 32 photos into 8 columns?


xavier.rayne

Recommended Posts

I know using table but i'm getting the photos from table image and it'll show all the images in one column.

I want it to sort into a table that consists 8 columns.

 

Below is my code:

<?php 

		 $query2 = "SELECT name FROM images";
		 $result2 = mysql_query($query2);
		 $quantity = mysql_num_rows($result2);  
		 while($row2 = mysql_fetch_array($result2)){
		 print_r($row2);
		 $ProImg2 = $row2;
		 echo "<tr>";
		 //for($i=0;$i<$quantity;$i++){

		 if($row2 %{	//sort the photos into 8 columns
		 $imgLoc2[$i]="mall/smallthumbnail.php?i=http://localhost/photo_album/mall/images/$ProImg2[$i]&w=50&h=50";
		?> 

		  <td><A onmouseover=replaceImage($i);><IMG style="CURSOR: hand" height=50 alt="pink" src="<?php echo $imgLoc2[$i];  ?>" width=50 border="0"></A></td>
		  <? } //end if($row2 %8 != 0)
		  else { 
				echo "</tr>";
				echo "<tr>";
				} 
			}//end for loop
				?>

 

Anyone here help me,please.....

Adjust your code accordingly...

 

 <?php 

		 $query2 = "SELECT name FROM images";
		 $result2 = mysql_query($query2);
		 $quantity = mysql_num_rows($result2);  


		 $colsPerRow = 8;
		 $i = 0;

		 while($row2 = mysql_fetch_array($result2)){
		 if ($i % $colsPerRow == 0) {
		// start a new row
		echo '<tr>';
	    ?>
		<td width="22" height="182"> </td>
            <td width="40%" valign="top">

		<table width="50%" border="0" cellpadding="0" cellspacing="0">
              <!--DWLayoutTable-->
              <tr>
                <td width="135" height="19" valign="top"><!--DWLayoutEmptyCell--> </td>
              </tr>
              <tr>
                <td height="136" valign="top">
			<? if($row2['$ProImg2']!=""){?>
			<img src="<?=$row2['$ProImg2']?>" alt="" width="135" height="136" border="0" /></td>
			<? } ?>

               </table>			</td>
            
              <?
	$i += 1;
	 } ?>
          </tr>

 

Hi..

According to your code:

<? if($row2['$ProImg2']!=""){?>
			<img src="<?=$row2['$ProImg2']?>" alt="" width="135" height="136" border="0" /></td>
			<? } ?>

 

I've try it already but then there is an error message appears:

Undefined index: $ProImg2

 

there are only Id and name fields in my image table and $ProImg2 = $row2

so i just changed the $row2['$ProImg2'] to $ProImg2[$i]...

but it just show one photo only :'(

 

Below is my edited code:

<?php 
		 //select images from table images(display all thumbnails for a category)
		 $query2 = "SELECT name FROM images";
		 $result2 = mysql_query($query2);
		 $quantity = mysql_num_rows($result2); 

		 $colsPerRow = 8;
		 $i = 0;
		  
		 while($row2 = mysql_fetch_array($result2)){
		  $ProImg2 = $row2;
		 if ($i % $colsPerRow == 0) {
		// start a new row
		echo '<tr>';

		 $imgLoc2[$i]="mall/smallthumbnail.php?i=http://localhost/photo_album/mall/images/$ProImg2[$i]&w=50&h=50";
		?> 

		  <td>
		  <? if($ProImg2[$i]!=""){?>
			 <A onmouseover=replaceImage($i);><IMG style="CURSOR: hand" height=50 alt="pink" src="<?php echo $imgLoc2[$i];  ?>" width=50 border="0"></A></td>
			<? } ?>

		  </table>
		  <?
	$i += 1;
	 } 
	 }?>
            </table>
		</tr>

 

Please help me.

Thanks :)

 

Here is the table structure for image:

 

CREATE TABLE `images` (
  `Id` int(11) NOT NULL auto_increment,
  `name` text,
  PRIMARY KEY  (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

 

 

The field name for image is name in table images.

 

Here is the table structure for image:

 

CREATE TABLE `images` (
  `Id` int(11) NOT NULL auto_increment,
  `name` text,
  PRIMARY KEY  (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

 

 

The field name for image is name in table images.

 

 

Does the name field save path to the images ?? Are u saving the path or not ??

 

Check this

 

<?php 
		 //select images from table images(display all thumbnails for a category)
		 $query2 = "SELECT name FROM images";
		 $result2 = mysql_query($query2);
		 $quantity = mysql_num_rows($result2); 

		 $colsPerRow = 8;
		 $i = 0;
		  
		 while($row2 = mysql_fetch_array($result2)){
		 $ProImg2 = $row2['name'];
		 if ($i % $colsPerRow == 0) {
		// start a new row
		echo '<tr>';
		// what is this for ???
		// $imgLoc2[$i]="mall/smallthumbnail.php?i=http://localhost/photo_album/mall/images/$ProImg2[$i]&w=50&h=50";
		?> 
		<? if($ProImg2!=""){?>	
		  <td>
		  <a href="" onmouseover=replaceImage(<?=$ProImg2?>);><IMG style="CURSOR: hand" alt="pink" src="<?=$ProImg2;?>" width="50" height="50" border="0"></A></td>
			<? } else { ?>
		 <td>No Image Found </td>
		 <? } ?>
		  </table>
		  <?
	$i += 1;
	 } 
	 }?>
            </table>
		</tr>

 

try

 <?php 

		 $query2 = "SELECT name FROM images";
		 $result2 = mysql_query($query2);
		 //$quantity = mysql_num_rows($result2);
//start table
                         echo '<table>';
//inicijalize $count
                         $count = 0;  
		 while($row2 = mysql_fetch_array($result2)){
		 //print_r($row2);
		 $ProImg2 = $row2[0];
		 if($count % 8 == 0) echo "<tr>";
		 //for($i=0;$i<$quantity;$i++){

		 //if($row2 %{	//sort the photos into 8 columns
		 $imgLoc2="mall/smallthumbnail.php?i=http://localhost/photo_album/mall/images/$ProImg2&w=50&h=50";
		?> 

		  <td><A onmouseover=replaceImage($i);><IMG style="CURSOR: hand" height=50 alt="pink" src="<?php echo $imgLoc2;  ?>" width=50 border="0"></A></td>
		  <? 
                         $count++;
                         if($count % 8 == 0) echo "</tr>";
//}
//end if($row2 %8 != 0)
//			  else { 
//					echo "</tr>";
//					echo "<tr>";
//					} 
//		}//end for loop
                if($count % 8 != 0) echo "</tr>";
                echo '</table>';
		 }                    
?>

Does the name field save path to the images ?? Are u saving the path or not ??

 

the name field did not save the path, it just save the filename.

 

// what is this for ???
		// $imgLoc2[$i]="mall/smallthumbnail.php?i=http://localhost/photo_album/mall/images/$ProImg2[$i]&w=50&h=50";

$imgLoc2[$i] is to show the path to the image.

 

i've try your code already but it didn't work.

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.