Thread: Paging Problem
View Single Post
Join Date: Aug 2007
Posts: 199
Reputation: tanha is an unknown quantity at this point 
Solved Threads: 0
tanha tanha is offline Offline
Junior Poster

Paging Problem

 
0
  #1
Sep 25th, 2007
Hello everybody,
I found paging code from www.plus2net.com, but when I implemented there is a problem with $this variable and the error is:
"Fatal error: Cannot re-assign $this in C:\wamp\www\Paging\php_paging.php on line 33"

This is the code:
  1. <?php
  2. //****************************************************************************
  3. ////////////////////////Downloaded from www.plus2net.com //////////////////////////////////////////
  4. /////////////////////// Visit www.plus2net.com for more such script and codes.
  5. //////// Read the readme file before using /////////////////////
  6. //////////////////////// You can distribute this code with the link to www.plus2net.com ///
  7. ///////////////////////// Please don't remove the link to www.plus2net.com ///
  8. //////////////////////////
  9. //*****************************************************************************
  10. ?>
  11. <!doctype html public "-//w3c//dtd html 3.2//en">
  12.  
  13. <html>
  14.  
  15. <head>
  16. <title>Plus2net.com paging script in PHP</title>
  17. <meta name="GENERATOR" content="Arachnophilia 4.0">
  18. <meta name="FORMATTER" content="Arachnophilia 4.0">
  19. </head>
  20.  
  21. <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
  22. <?php
  23. require "config.php"; // All database details will be included here
  24.  
  25. $page_name="php_paging.php"; // If you use this code with a different page ( or file ) name then change this
  26.  
  27. if(!isset($start)) { // This variable is set to zero for the first page
  28. $start = 0;
  29. }
  30.  
  31. $eu = ($start -0);
  32. $limit = 2; // No of records to be shown per page.
  33. $this = $eu + $limit;
  34. $back = $eu - $limit;
  35. $next = $eu + $limit;
  36.  
  37.  
  38. /////////////// WE have to find out the number of records in our table. We will use this to break the pages///////
  39. $query2=" SELECT * FROM student_adv ";
  40. $result2=mysql_query($query2);
  41. echo mysql_error();
  42. $nume=mysql_num_rows($result2);
  43. /////// The variable nume above will store the total number of records in the table////
  44.  
  45. /////////// Now let us print the table headers ////////////////
  46. $bgcolor="#f1f1f1";
  47. echo "<TABLE width=50% align=center cellpadding=0 cellspacing=0> <tr>";
  48. echo "<td bgcolor='dfdfdf' >&nbsp;<font face='arial,verdana,helvetica' color='#000000' size='4'>ID</font></td>";
  49.  
  50. echo "<td bgcolor='dfdfdf' >&nbsp;<font face='arial,verdana,helvetica' color='#000000' size='4'>Name</font></td>";
  51. echo "<td bgcolor='dfdfdf' >&nbsp;<font face='arial,verdana,helvetica' color='#000000' size='4'>Class</font></td>";
  52. echo "<td bgcolor='dfdfdf'>&nbsp;<font face='arial,verdana,helvetica' color='#000000' size='4'>Mark</font></td></tr>";
  53.  
  54. ////////////// Now let us start executing the query with variables $eu and $limit set at the top of the page///////////
  55. $query=" SELECT * FROM student_adv limit $eu, $limit ";
  56. $result=mysql_query($query);
  57. echo mysql_error();
  58.  
  59. //////////////// Now we will display the returned records in side the rows of the table/////////
  60. while($noticia = mysql_fetch_array($result))
  61. {
  62. if($bgcolor=='#f1f1f1'){$bgcolor='#ffffff';}
  63. else{$bgcolor='#f1f1f1';}
  64.  
  65. echo "<tr >";
  66. echo "<td align=left bgcolor=$bgcolor id='title'>&nbsp;<font face='Verdana' size='2'>$noticia[id]</font></td>";
  67.  
  68. echo "<td align=left bgcolor=$bgcolor id='title'>&nbsp;<font face='Verdana' size='2'>$noticia[name]</font></td>";
  69. echo "<td align=left bgcolor=$bgcolor id='title'>&nbsp;<font face='Verdana' size='2'>$noticia[class]</font></td>";
  70. echo "<td align=left bgcolor=$bgcolor id='title'>&nbsp;<font face='Verdana' size='2'>$noticia[mark]</font></td>";
  71.  
  72. echo "</tr>";
  73. }
  74. echo "</table>";
  75. ////////////////////////////// End of displaying the table with records ////////////////////////
  76.  
  77. ///// Variables set for advance paging///////////
  78. $p_limit=8; // This should be more than $limit and set to a value for whick links to be breaked
  79. if(!isset($p_f)){$p_f=0;}
  80. $p_fwd=$p_f+$p_limit;
  81. $p_back=$p_f-$p_limit;
  82. //////////// End of variables for advance paging ///////////////
  83. /////////////// Start the buttom links with Prev and next link with page numbers /////////////////
  84. echo "<table align = 'center' width='50%'><tr><td align='left' width='20%'>";
  85. if($p_f<>0){print "<a href='$page_name?start=$p_back&p_f=$p_back'><font face='Verdana' size='2'>PREV $p_limit</font></a>"; }
  86. echo "</td><td align='left' width='10%'>";
  87. //// if our variable $back is equal to 0 or more then only we will display the link to move back ////////
  88. if($back >=0 and ($back >=$p_f)) {
  89. print "<a href='$page_name?start=$back&p_f=$p_f'><font face='Verdana' size='2'>PREV</font></a>";
  90. }
  91. //////////////// Let us display the page links at center. We will not display the current page as a link ///////////
  92. echo "</td><td align=center width='30%'>";
  93. for($i=$p_f;$i < $nume and $i<($p_f+$p_limit);$i=$i+$limit){
  94. if($i <> $eu){
  95. $i2=$i+$p_f;
  96. echo " <a href='$page_name?start=$i&p_f=$p_f'><font face='Verdana' size='2'>$i</font></a> ";
  97. }
  98. else { echo "<font face='Verdana' size='4' color=red>$i</font>";} /// Current page is not displayed as link and given font color red
  99.  
  100. }
  101.  
  102.  
  103. echo "</td><td align='right' width='10%'>";
  104. ///////////// If we are not in the last page then Next link will be displayed. Here we check that /////
  105. if($this < $nume and $this <($p_f+$p_limit)) {
  106. print "<a href='$page_name?start=$next&p_f=$p_f'><font face='Verdana' size='2'>NEXT</font></a>";}
  107. echo "</td><td align='right' width='20%'>";
  108. if($p_fwd < $nume){
  109. print "<a href='$page_name?start=$p_fwd&p_f=$p_fwd'><font face='Verdana' size='2'>NEXT $p_limit</font></a>";
  110. }
  111. echo "</td></tr></table>";
  112.  
  113.  
  114. ?>
  115. <center><a href='http://www.plus2net.com'>PHP SQL HTML free tutorials and scripts</a></center>
  116. </body>
  117.  
  118. </html>
Reply With Quote