473,574 Members | 3,174 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pagination - First page works great, next pages are blank

21 New Member
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, and the pagination almost works. The first page of the pagination works fine, but when I click on one of the links for one of the next pages, the page is blank.

I have seen people mention this problem, and they have been told that a variable is not being passed to the next pages. So I have experimented passing variables using both the session method and the get method, and nothing seems to work. The code below shows "?currentpage=2 &find=miami" at the end of the URL of the next pages for the topic "miami," but the page is blank.

Any ideas why this pagination is not working for the next pages?

Thanks,

John




Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3. $find = strip_tags($find);
  4. $find = trim ($find);
  5. $find = strtolower($find);
  6. $_SESSION['find'] = $find;
  7.  
  8.  
  9.  
  10. mysql_connect("mysqlv3", "username", "password") or die(mysql_error());
  11. mysql_select_db("sand2") or die(mysql_error());
  12.  
  13. // We preform a bit of filtering
  14.  
  15.  
  16. $find = strip_tags($find);
  17. $find = trim ($find);
  18. $find = strtolower($find);
  19.  
  20. $_GET['find'] = (isset($_POST['find'])) ? $_POST['find'] : $_GET['find'];
  21. $_GET['find'] = strtolower($_GET['find']);
  22.  
  23. $result=mysql_query("SHOW TABLES FROM sand2 LIKE '%$find%'")
  24. or die(mysql_error());
  25.  
  26. $_GET['result'] = $result;
  27.  
  28. if(mysql_num_rows($result)>0){
  29. while($table=mysql_fetch_row($result)){
  30.  
  31. $_GET[`$table[0]`] = $table;
  32. $_SESSION['table']= $table;
  33.  
  34. $presult = mysql_query("SELECT COUNT(*) FROM `$table[0]`") or die(mysql_error());
  35.  
  36. $rr = mysql_fetch_row($presult);  
  37. $numrows = $rr[0]; 
  38. $rowsperpage = 20; 
  39. $totalpages = ceil($numrows / $rowsperpage);
  40.  
  41. // get the current page or set a default  
  42. if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {  
  43.    // cast var as int  
  44.    $currentpage = (int) $_GET['currentpage'];  
  45. } else {  
  46.    // default page num  
  47.    $currentpage = 1;  
  48. } // end if  
  49.  
  50. // if current page is greater than total pages...  
  51. if ($currentpage > $totalpages) {  
  52.    // set current page to last page  
  53.    $currentpage = $totalpages;  
  54. } // end if  
  55. // if current page is less than first page...  
  56. if ($currentpage < 1) {  
  57.    // set current page to first page  
  58.    $currentpage = 1;  
  59. } // end if  
  60.  
  61. // the offset of the list, based on current page   
  62. $offset = ($currentpage - 1) * $rowsperpage; 
  63.  
  64.  
  65. print "<p class=\"topic\">$table[0]</p>\n";
  66. $r=mysql_query("SELECT * , votes_up - votes_down AS effective_vote FROM `$table[0]` ORDER BY effective_vote DESC LIMIT $offset, $rowsperpage");
  67.  
  68. $_GET[`$r[0]`] = $r;
  69.  
  70. print "<table class=\"navbar\">\n";
  71. while($row=mysql_fetch_array($r)){
  72.  
  73. $_GET[`$row[0]`] = $row;
  74. $_SESSION['row']= $row;
  75.  
  76. $effective_vote = $row['votes_up'] - $row['votes_down']; 
  77.  
  78. print "<tr>";
  79.  
  80. print "<td>".'<a href="http://'.$row['site'].'" class="links2">'.$row['site'].'</a>'."</td>";
  81. print "<td class='votes'>".'<span class="votes_count" id="votes_count'.$row['id'].'">'.number_format($effective_vote).'</span>'."</td>";
  82. print "<td class='ballot'>".'<span class="button" id="button'.$row['id'].'">'.'<a href="javascript:;" class="cell1" id="'.$row['id'].'">'.Vote.'</a>'.'</span>'."</td>";
  83. }
  84. print "</tr>\n";
  85. }
  86. print "</table>\n";
  87.  
  88.  
  89. $range = 3;  
  90.  
  91. /******  build the pagination links ******/  
  92. // range of num links to show    
  93.  
  94. // if not on page 1, don't show back links  
  95. if ($currentpage > 1) {  
  96.    // show << link to go back to page 1  
  97.    echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1&find={$_SESSION['find']}'><<</a> ";  
  98.    // get previous page num  
  99.    $prevpage = $currentpage - 1;  
  100.    // show < link to go back to 1 page  
  101.    echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage&find={$_SESSION['find']}'><</a> ";  
  102. } // end if   
  103.  
  104. // loop to show links to range of pages around current page  
  105. for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {  
  106.    // if it's a valid page number...  
  107.    if (($x > 0) && ($x <= $totalpages)) {  
  108.       // if we're on current page...  
  109.       if ($x == $currentpage) {  
  110.          // 'highlight' it but don't make a link  
  111.          echo " [<b>$x</b>] ";  
  112.       // if not current page...  
  113.       } else {  
  114.          // make it a link  
  115.      echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x&find={$_SESSION['find']}'>$x</a> ";  
  116.       } // end else  
  117.    } // end if   
  118. } // end for  
  119.  
  120. // if not on last page, show forward and last page links      
  121. if ($currentpage != $totalpages) {   
  122.    // get next page  
  123.    $nextpage = $currentpage + 1;  
  124.     // echo forward link for next page   
  125.    echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage&find={$_SESSION['find']}'>></a> ";  
  126.    // echo forward link for lastpage  
  127.    echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages&find={$_SESSION['find']}'>>></a> ";  
  128. } // end if  
  129. /****** end build pagination links ******/  
  130.  
  131.  
  132. }
  133.  
  134.  
  135.  
  136. else{
  137. print "None found";
  138. }
  139.  
  140.  
  141.  
  142.  
  143. //This counts the number or results - and if there wasn't any it gives them a little message explaining that
  144. $anymatches=mysql_num_rows($result);
  145. if ($anymatches == 0)
  146. {
  147. echo "Sorry, but we can not find an entry to match your query<br><br>";
  148. unset($_SESSION['find']);    
  149.  
  150. }
  151.  
  152.  
  153. }
  154. ?>
  155.  
  156.  
May 27 '09 #1
4 3561
prabirchoudhury
162 New Member
hey, you dont need to assign $_session for the [ next ] [previous] page .. have a look on

Pagination Problem
May 28 '09 #2
ArizonaJohn
21 New Member
Hi Prabirchoudhury ,

Could you be more specific? What variable does not need a $_session?

Thanks,

John
May 28 '09 #3
prabirchoudhury
162 New Member
ok..
you are doing simple pagination so for that you need
1. dont need to assign $_SESSION['find'] = $find; to store and carry your variable $find.

2. you are passing $find already through query string (with next and previous page url) , so from the next page you could get this $find frm $_GET[find] and use it and pass again through the query string.

3. and make sure you are getting all the variables you need for the next page.

echo all the variables and make sure you are nor missing passed to the next page.

may be your session is unset($_SESSION['find']); in the bottom condition
May 28 '09 #4
ArizonaJohn
21 New Member
Hi,

I tried using &find={$_GET['find']}, and the variable is indeed being passed through. I can tell by the URL of the next pages.

However, the results are still blank.

Maybe "find" is the wrong variable for me to be passing through? After all, this is the result that I am breaking up into pagination:

Expand|Select|Wrap|Line Numbers
  1. $result=mysql_query("SHOW TABLES FROM sand2 LIKE '%$find%'")
  2. or die(mysql_error());
  3.  
  4. if(mysql_num_rows($result)>0){
  5. while($table=mysql_fetch_row($result)){
  6.  
  7. print "<p class=\"topic\">$table[0]</p>\n";
  8. $r=mysql_query("SELECT * , votes_up - votes_down AS effective_vote FROM `$table[0]` ORDER BY effective_vote DESC LIMIT $offset, $rowsperpage");
  9.  
  10.  
  11. print "<table class=\"navbar\">\n";
  12. while($row=mysql_fetch_array($r)){
  13.  
May 28 '09 #5

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

Similar topics

11
2754
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. This works great and opens all images in the database when I open the url mywebsite/gallery.php, or I can choose certain images (by category) by...
0
1451
by: Sheau Wei | last post by:
I am using php version 4.3.3. The below was my pagination code. My problem is that when i run this code in my computer, i wall fail because of the hyperlink of the pagination not function when i click it. But when i run in other people computer, It was no problem at all. I wonder to know what wrong to my coding . Is it different version of php...
3
2122
by: assgar | last post by:
Hello I have a search page where you select the letter of the alphabet and the person's information who's name beginning with that letter is displayed. This function is placed on the web page to search and display the information. Everything works except one thing. The problem is if there are 3 pages page one is OK, but when you...
1
3368
by: assgar | last post by:
Hi I was using a schroll bar to display multiple rows of dynamically created from database records. The scrolling was not displaying the data properly so I have decided to use pagination. The problem I am having is, if I select one item on page #1 and another on page #5 only the last item selected on page #5 is stored in the array. How...
1
6840
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 i have written for pagination but it displays the link of all the pages at one go i.e. if i have 8 pages showing 10 results per page than it shows...
3
1577
by: raaman rai | last post by:
Please help me with the following code. I have used this pagination script from the net and customized it but unfortunately it doesnt work as expected. The problem is, for the trial purpose i have 3 records in the table and i have set the limit value to 2 only for now (for trial). So it is expected that i have 2 records displayed in the first page...
16
2757
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) { $page = (int)$_GET; } else { $page = 1; } // start fetching from this row number $offset = ($page - 1) *...
1
3548
markrawlingson
by: markrawlingson | last post by:
Hello, For starters: Yes, I am new to asp.net, however I hold a good 9-10 years of experience working with classic asp and am only just now upgrading my skills. I'm picking asp.net up pretty quickly but I'm running into a stumbling block that I just can't seem to get around. I think I know what the problem is, and I'm pretty confident in a...
2
2586
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 kindly help <?php session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
0
7841
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8270
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7856
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5651
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5335
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3773
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3793
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2270
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1369
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.