xavier.rayne Posted September 13, 2007 Share Posted September 13, 2007 Hi, there. i want to sort a collection of photos into 8 columns...but i don't know how to do it? Let's say a user inserts 26 photos and i want to sort it in 8 columns and 4 rows, how can it be done? Can i use modulo?but i'm not familiar with it :-\ Quote Link to comment https://forums.phpfreaks.com/topic/69144-how-to-sort-32-photos-into-8-columns/ Share on other sites More sharing options...
Jessica Posted September 13, 2007 Share Posted September 13, 2007 Uhm...make a table in html. Quote Link to comment https://forums.phpfreaks.com/topic/69144-how-to-sort-32-photos-into-8-columns/#findComment-347547 Share on other sites More sharing options...
xavier.rayne Posted September 13, 2007 Author Share Posted September 13, 2007 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..... Quote Link to comment https://forums.phpfreaks.com/topic/69144-how-to-sort-32-photos-into-8-columns/#findComment-347562 Share on other sites More sharing options...
watthehell Posted September 13, 2007 Share Posted September 13, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/69144-how-to-sort-32-photos-into-8-columns/#findComment-347563 Share on other sites More sharing options...
xavier.rayne Posted September 13, 2007 Author Share Posted September 13, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/69144-how-to-sort-32-photos-into-8-columns/#findComment-347575 Share on other sites More sharing options...
watthehell Posted September 13, 2007 Share Posted September 13, 2007 Can you post your Table Structure ??? What is the field name of the image in DB ??? Quote Link to comment https://forums.phpfreaks.com/topic/69144-how-to-sort-32-photos-into-8-columns/#findComment-347578 Share on other sites More sharing options...
xavier.rayne Posted September 13, 2007 Author Share Posted September 13, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/69144-how-to-sort-32-photos-into-8-columns/#findComment-347593 Share on other sites More sharing options...
watthehell Posted September 13, 2007 Share Posted September 13, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/69144-how-to-sort-32-photos-into-8-columns/#findComment-347659 Share on other sites More sharing options...
sasa Posted September 13, 2007 Share Posted September 13, 2007 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>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/69144-how-to-sort-32-photos-into-8-columns/#findComment-347815 Share on other sites More sharing options...
freakus_maximus Posted September 13, 2007 Share Posted September 13, 2007 There is a post in the FAQ/Code Snippet forum that explains how to do this. http://www.phpfreaks.com/forums/index.php/topic,95426.0.html Quote Link to comment https://forums.phpfreaks.com/topic/69144-how-to-sort-32-photos-into-8-columns/#findComment-347829 Share on other sites More sharing options...
xavier.rayne Posted September 14, 2007 Author Share Posted September 14, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/69144-how-to-sort-32-photos-into-8-columns/#findComment-348233 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.