Connecting Tech Pros Worldwide Forums | Help | Site Map

paginationerror...image only in rows n not in columns

Member
 
Join Date: Apr 2009
Posts: 103
#1: Jun 24 '09
i m trying to display the result images in table format or rows and columns but the cod i wrote displays them only in rows....someone plz help

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3.  
  4. // generating a array with image paths
  5.  
  6. $query_images = "SELECT image_path,image_name FROM userfolders" ;
  7. $result_images = mysql_query($query_images);
  8. confirm_query($result_images);
  9.  
  10. while ($record_images = mysql_fetch_assoc($result_images)) {
  11.           $file = $record_images['image_name'] ;
  12.           $dirname = $record_images['image_path'] ;
  13.  
  14.  
  15. // generating a thumbnail
  16. $thumb_height = 100;
  17. $filename = $dirname."/".$file;
  18. $filename_array[] = $filename ;
  19. list($width, $height) = getimagesize($filename);
  20.         $ratio = ($height/$width);
  21.         $ratio_array[] = $ratio;
  22.         $newheight = $thumb_height;
  23.         $newheight_array[] = $newheight;
  24.         $newwidth = ($thumb_height/$ratio);
  25.         $newwidth_array[] = $newwidth;
  26.  
  27. $page = empty($_GET['page']) ? 1 : $_GET['page'];
  28. $num_per_page = 4;
  29. $total_pages = ceil(count($filename_array)/$num_per_page);
  30.  
  31. }
  32.  
  33. ?>
  34.  
  35. <?php
  36. for($i = ($page - 1) * $num_per_page; $i < $page * $num_per_page; $i++)
  37. {?><li><a href="<?php echo $filename_array[$i]; ?>">
  38. <img src="<?php echo $filename_array[$i]; ?>" width="<?php echo $newwidth_array[$i]; ?>" height="<?php echo $thumb_height_array[$i]; ?>" align="top"
  39. alt="<?php echo $filename_array[$i]; ?>" /></a></li>
  40. <?php
  41. }
  42. ?>
  43.  
  44. <?php
  45. echo "</ul>";
  46. $pages = array();
  47. for($i = 1; $i <= $total_pages; $i++) {
  48. $pages[] = "<a href=\"".$_SERVER['PHP_SELF']."?page=".$i."\">".$i."</a>";
  49. }
  50. echo "Page: ".implode(" ", $pages);
  51.  
  52. ?>
  53.  

prabirchoudhury's Avatar
Familiar Sight
 
Join Date: May 2009
Location: Wellington, New Zealand
Posts: 159
#2: Jun 25 '09

re: paginationerror...image only in rows n not in columns


1. ok, you need make a table and run your forloop inside that table
2. when you run for loop then after a selected no of <td> you need to make a new <tr> to make another row.

3. we geting all say 100 images in one row. how can we make it so that every 10th (could change this no, you want) image ends the row, and starts a new one? could use the Modulus arithmetic operand to calculate that. The operand sign is the percent sign (%). So you set up our if() statement thusly:


Expand|Select|Wrap|Line Numbers
  1.  
  2. <table align=center border=0 >
  3. <tbody>
  4. <tr>
  5. for ($i=1; $i<= $total_pages; $i++)
  6. {
  7.  
  8. $pages = "<a href=\"".$_SERVER['PHP_SELF']."?page=".$i."\">".$i."</a>";
  9.   echo('<TD align=top>');
  10.   echo $pages; 
  11.   echo('</TD>');
  12.   if($i % 10 == 0)
  13.         {
  14.           echo '</tr>
  15.           <tr>';
  16.         }
  17.  
  18. }
  19.  
  20. </TBODY>
  21. </TABLE>
  22.  
  23.  
:))
Member
 
Join Date: Apr 2009
Posts: 103
#3: Jul 14 '09

re: paginationerror...image only in rows n not in columns


well i did wat u told me its still not working.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. // generating a array with image paths
  4.  
  5. $query_images = "SELECT image_path,image_name FROM userfolders" ;
  6. $result_images = mysql_query($query_images);
  7. confirm_query($result_images);
  8.  
  9. while ($record_images = mysql_fetch_assoc($result_images)) {
  10.           $file = $record_images['image_name'] ;
  11.           $dirname = $record_images['image_path'] ;
  12.  
  13.  
  14. // generating a thumbnail
  15. $thumb_height = 100;
  16. $filename = $dirname."/".$file;
  17. $filename_array[] = $filename ;
  18. list($width, $height) = getimagesize($filename);
  19.         $ratio = ($height/$width);
  20.         $ratio_array[] = $ratio;
  21.         $newheight = $thumb_height;
  22.         $newheight_array[] = $newheight;
  23.         $newwidth = ($thumb_height/$ratio);
  24.         $newwidth_array[] = $newwidth;
  25.  
  26. $page = empty($_GET['page']) ? 1 : $_GET['page'];
  27. $num_per_page = 4;
  28. $total_pages = ceil(count($filename_array)/$num_per_page);
  29.  
  30. }
  31.  
  32. ?>
  33.  
  34. <?php
  35. for($i = ($page - 1) * $num_per_page; $i < $page * $num_per_page; $i++)
  36. {?><li><a href="<?php echo $filename_array[$i]; ?>">
  37. <img src="<?php echo $filename_array[$i]; ?>" width="<?php echo $newwidth_array[$i]; ?>" height="<?php echo $thumb_height_array[$i]; ?>" align="top"
  38. alt="<?php echo $filename_array[$i]; ?>" /></a></li>
  39. <?php
  40. }
  41. ?>
  42.  
  43.  
  44.  
  45.  
  46.  
  47. <?php
  48. echo "</ul>";
  49. $pages = array();
  50. ?>
  51. <table align=center border=0 >
  52. <tbody>
  53. <tr>
  54. <?php
  55.  
  56. for ($i=1; $i<= $total_pages; $i++)
  57. {
  58.  
  59. $pages = "<a href=\"".$_SERVER['PHP_SELF']."?page=".$i."\">".$i."</a>";
  60.   echo('<TD align=top>');
  61.   echo $pages; 
  62.   echo('</TD>');
  63.   if($i % 10 == 0)
  64.         {
  65.           echo '</tr>
  66.           <tr>';
  67.         }
  68.  
  69. }
  70. ?>
  71.  
  72. </TBODY>
  73. </TABLE>
  74.  
  75.  
Reply