473,385 Members | 1,337 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Pagination

I am attempting to add script to limit the number of images displayed per page. The images to be displayed in 2 columns. The script I have used I obtained from searching "PHP Pagination" via Google, it seemed to work fine until I tried to added the code to put the images diplayed into 2 columns. Each set of code worked OK on its own! Any help would be appreciated.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $Host="mysql1.namesco.net";
  4. $User="usedcarsgbco";
  5. $Password="031255";
  6. $DBName = "usedcarsgbco";
  7. $TableName = "VehicleStock";
  8. $TablePhoto = "cpg140_pictures";
  9. $Link = mysql_connect ($Host, $User, $Password);
  10. $Query =  "SELECT * FROM VehicleStock LEFT JOIN cpg140_pictures ON VehicleStock.RegNo = cpg140_pictures.title ORDER BY CarID DESC";
  11. $Result = mysql_db_query ($DBName, $Query, $Link);
  12.  
  13. $max = 4;
  14. $p = $_GET['p'];
  15. if(empty($p))
  16. {
  17. $p = 1;
  18. }
  19. $limits = ($p - 1) * $max;
  20. //view the news article!
  21. if(isset($_GET['act']) && $_GET['act'] == "view")
  22. {
  23. $id = $_GET['RegNo'];
  24. $sql = mysql_query("SELECT * FROM VehicleStock");
  25. while($r = mysql_fetch_array($sql))
  26. {
  27. $RegNo = $r['RegNo'];
  28. $Price = $r['Price'];
  29.  
  30. echo "<div><p>$RegNo</p><p>$Price</p></div>";
  31. }
  32.  
  33. }else{
  34.  
  35.  
  36. $sql = mysql_query("SELECT * FROM VehicleStock LIMIT ".$limits.",$max") or die(mysql_error());
  37. $totalres = mysql_result(mysql_query("SELECT COUNT(RegNo) AS tot FROM VehicleStock"),0); 
  38. $totalpages = ceil($totalres / $max);
  39.  
  40. echo "<table align=center><tr><td>Reg No</td><td>Retail Price</td></tr><tr>";
  41. $_counter = -1; 
  42. $_cols = 2;
  43.  
  44. {
  45. $id = $r['RegNo'];
  46. $RegNo = $r['RegNo'];
  47. $Price = $r['Price'];
  48. //(NEXT 28 LINES OF SCRIPT DISPLAY IMAGES IN 2 COLUMNS)
  49. $_pos = ( ++$_counter % $_cols );
  50.         if( $_pos === 0 )
  51. {
  52.         echo '
  53.         <tr>';
  54.     }
  55. echo "<tr><td><a href='VehicleDetail.php?act=view&RegNo=$id&Price=$Price'>
  56.         <img border='0'alt='Click for car details' src=gallery/albums/userpics/10001/$RegNo.jpg></a></td><td>£$Price</td>";
  57. }
  58. echo "</tr></table>";
  59. if( $_pos === $_cols - 1 )
  60.     {
  61.         echo '
  62.         </tr>';
  63.     }
  64. }
  65.  
  66. if( $_counter % $_cols !== $_cols - 1 )
  67. {
  68.     do
  69.     {
  70.         echo '
  71.             <td style="visibility: hidden">&nbsp;</td>';
  72.     }
  73.     while( ++$_counter % $_cols !== $_cols - 1 );
  74.  
  75.     echo '
  76.         </tr>';
  77. //END OF IMAGE DISPLAY SCRIPT
  78. }
  79. for($i = 1; $i <= $totalpages; $i++){
  80.  
  81. echo "<a href='StockTest.php?p=$i'>$i</a>|";
  82. }
  83.  
  84.  
  85. ?>
  86. </body>
  87. </html>
  88.  
  89.  
  90.  
Jun 9 '08 #1
5 1137
Markus
6,050 Expert 4TB
Let me get this right, you're wanting to display images in two columns?

i.e:
Expand|Select|Wrap|Line Numbers
  1. img1 - img2
  2. img3 - img4
  3. img5 - img6
  4.  
  5. // etc..
  6.  
Also, please remeber to use code tags properly when posting code.
Jun 9 '08 #2
Yes thats correct!
Also I did notice I missed a "]" , but it was too late to amend.

Have been playing with my code and so far am unable to display just 4 images per page. But do have the links appearing to offer further pages! I feel I am close but that some of the code is in the wrong place. Your help would really be appreciated.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $Host="mysql1.namesco.net";
  4. $User="usedcarsgbco";
  5. $Password="031255";
  6. $DBName = "usedcarsgbco";
  7. $TableName = "VehicleStock";
  8. $TablePhoto = "cpg140_pictures";
  9. $Link = mysql_connect ($Host, $User, $Password);
  10. $Query =  "SELECT * FROM VehicleStock LEFT JOIN cpg140_pictures ON VehicleStock.RegNo = cpg140_pictures.title ORDER BY CarID DESC"; 
  11. $Result = mysql_db_query ($DBName, $Query, $Link);
  12. $max = 4;
  13. $p = $_GET['p'];
  14. if(empty($p))
  15. {
  16. $p = 1;
  17. }
  18. $limits = ($p - 1) * $max;
  19.  
  20. if(isset($_GET['act']) && $_GET['act'] == "view")
  21. {
  22. $id = $_GET['RegNo'];
  23. $sql = mysql_query("SELECT * FROM VehicleStock");
  24. while($r = mysql_fetch_array($sql))
  25. {
  26. $RegNo = $r['RegNo'];
  27. $Price = $r['Price'];
  28. }
  29. }else{
  30. $sql = mysql_query("SELECT * FROM VehicleStock LIMIT ".$limits.",$max") or die(mysql_error());
  31. $totalres = mysql_result(mysql_query("SELECT COUNT(RegNo) AS tot FROM VehicleStock"),0); 
  32. $totalpages = ceil($totalres / $max);
  33. }
  34.  
  35.  
  36.  
  37. echo "<div><p>$RegNo</p><p>$Price</p></div>";
  38.  
  39.  
  40. for($i = 1; $i <= $totalpages; $i++){
  41.  
  42. echo "<a href='StockTestAll1.php?p=$i'>$i</a>|";
  43. }
  44.  
  45. echo '
  46. <table align=center>';
  47.  
  48. $_counter = -1;  // We start 'outside' the Matrix.  Unlike Neo.
  49. $_cols = 2; // 3 columns.  Of the Ionic variety.
  50. while( $__row = mysql_fetch_assoc($Result) )
  51. {
  52.     // Advance the counter and determine our 'position';
  53.     $_pos = ( ++$_counter % $_cols );
  54.  
  55.     // Should we output a '<tr>'?
  56.     if( $_pos === 0 )
  57. {
  58.         echo '
  59.         <tr>';
  60.     }
  61.  
  62.         echo "
  63.  
  64. <td><table>
  65.     <tr><td colspan=3 class='SLMakeModel'><b> &nbsp;{$__row['Make']}&nbsp;{$__row['Spec']}</b></td></tr>
  66.  
  67.     <tr><td><a href='VehicleDetail.php?RegNo=$__row[RegNo]&Price=$__row[Price]'>
  68.         <img border='0'alt='Click for details' src=gallery/albums/$__row[filepath]$__row[filename] width='225' height='175'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a> 
  69.     <td valign='top'class='SLTransmissionText'><b>Registered:</b><br>{$__row['RegDate']}<br>&nbsp;<br>
  70.     <b>Transmission:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>{$__row['Box']}<br>&nbsp;<br>
  71.     <b>Mileage:</b><br>{$__row['Mileage']}<br>&nbsp;<br>
  72.     <b>Price:</b><br>£{$__row['Price']}
  73.     </tr> </td>
  74.  
  75.     <Tr><td  colspan=3 class='SLMakeModel'><a href='VehicleDetail.php?RegNo=$__row[RegNo]&Price=$__row[Price]'><img border='0' alt='Click for Details'src=Images/details.gif> </a></td></tr>
  76.  
  77.  
  78.  
  79. <tr> <td>
  80.  
  81.  
  82. </td></tr></table>         </td>";
  83.  
  84.  
  85.  
  86.     // Should we output a '</tr>'?
  87.     if( $_pos === $_cols - 1 )
  88.     {
  89.         echo '
  90.         </tr>';
  91.     }
  92. }
  93.  
  94.  
  95.  
  96. if( $_counter % $_cols !== $_cols - 1 )
  97. {
  98.     do
  99.     {
  100.         echo '
  101.             <td style="visibility: hidden">&nbsp;</td>';
  102.     }
  103.     while( ++$_counter % $_cols !== $_cols - 1 );
  104.  
  105.     echo '
  106.         </tr>';
  107. }
  108.  
  109. echo '
  110. </table>';
  111. ?>
  112.  
  113.  
Jun 9 '08 #3
Markus
6,050 Expert 4TB
Yes thats correct!
Also I did notice I missed a "]" , but it was too late to amend.

Have been playing with my code and so far am unable to display just 4 images per page. But do have the links appearing to offer further pages! I feel I am close but that some of the code is in the wrong place. Your help would really be appreciated.
In fact, a few months back I had the same problem. Pbmods came up with a great solution. I'll just have to search the archives and find it!

2 mins.
Jun 9 '08 #4
Markus
6,050 Expert 4TB
Here you go

Hope it helps!
Jun 9 '08 #5
Thanks for that, this is where I got my code from to limit the images per page. My problem from there was to create the links to the next 4 images etc. When I inserted the code to paginate I ended up with the links OK but lost the 4 images per page and got the whole array.

The code (I think) is all there but must be in the wrong order. Any ideas?
Jun 9 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Sharif T. Karim | last post by:
Anyone know of a up-to-date tutorial for pagination where I can have it like: Prev 1 2 3 4 Next Thanks. -- Sharif T. Karim ....you don't know wrath yet...
1
by: Faree | last post by:
I am workign on a news portal which needs paginaiton as usual.but all the code i got depends on the number of records that will come from database :( .it is working well too. But i need...
1
by: Kruq | last post by:
Is it possible to use pagination with DataList? Can't find it.. :( Kruq
2
by: Chris H | last post by:
I am having a problem with pagination, basically the problem is happening in the "PREV / NUMBERS / NEXT" links, it appears as if the reason is becasue the increment and decrement operators aren't...
11
by: ste | last post by:
Hi there, Further to my recent posts where I've received excellent help from Rik and Jerry, I've ended up with an image gallery on my website that displays images in a table, 3 images per row. ...
1
by: dhanu | last post by:
How to manage pagination in AJAX? My requirement is similar to GMails inbox feature. Whenever a new mail comes in,the newly arrived mail is at the start of my inbox and last row in that page...
1
by: shalini jain | last post by:
Hi, I want to know how can we do pagination using XSL. There are number of tutorials available on pagination using PHP but nothing with XSL. i am really stuck with my code. Below is the code that...
16
by: gnawz | last post by:
I have a pagination function I am using in a file called functions.php as below<? //Pagination functions function getPagingQuery($sql, $itemPerPage = 10) { if (isset($_GET) && (int)$_GET > 0) ...
4
by: ArizonaJohn | last post by:
Hello, The code below works great. The user enters a name into an HTML form, the code looks up a table with that name, and then that table is displayed. I am trying to use pagination with it,...
2
by: kkshansid | last post by:
this is my search page on which i am getting two parameters from previous page but the problem is that as soon as i click any other next pages my sql query fails as it doesnt get these two parameters...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.