pagination not displaying results

Thread Solved

Join Date: Jul 2005
Posts: 20
Reputation: ploppy is an unknown quantity at this point 
Solved Threads: 0
ploppy ploppy is offline Offline
Newbie Poster

pagination not displaying results

 
0
  #1
Oct 17th, 2007
hi. i wonder if someone could check this script for me and tell why it isn't producing any results. here is the code:

  1.  
  2. <?php
  3. function ShowMyFiles() {
  4.  
  5. // vars global configuration
  6. global $dbConn, $theme_path;
  7.  
  8. // vars messages
  9. global $msg;
  10. // vars template
  11. global $error_msg, $status, $files, $owner, $test, $paginated;
  12.  
  13. if ($err) {
  14. $error_msg = 'Custom error message';
  15. }
  16.  
  17. if(!isset($_GET['page'])){
  18. $page = 1;
  19. } else {
  20. $page = $_GET['page'];
  21. }
  22.  
  23. // get variable after selecting something from the dropdown with name 'chooser'
  24. $select = $_POST['select'];
  25.  
  26.  
  27. // if something has been chosen
  28. if (!empty($select)) {
  29.  
  30. // get the chosen value
  31. $chooser = $_POST['chooser'];
  32.  
  33. // Define the number of results per page
  34. $max_results = 10;
  35.  
  36. // Figure out the limit for the query based
  37. // on the current page number.
  38. $from = (($page * $max_results) - $max_results);
  39.  
  40. // get file listing
  41. // if everything successful create query
  42. // this selects all rows where the type is the one you chose in the dropdown
  43. // * means that it will select all columns, ie name and type as i said above
  44.  
  45. $sql = "SELECT title, description, date FROM idx_reslink WHERE category_id='$chooser' LIMIT $from, $max_results";
  46. $result = $dbConn->Execute($sql) or die(mysql_error());
  47.  
  48.  
  49. // Figure out the total number of results in DB:
  50. $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM idx_reslink WHERE category_id='$chooser'"),0);
  51.  
  52.  
  53. // Figure out the total number of pages. Always round up using ceil()
  54. $lastpage = ceil($total_results / $max_results);
  55.  
  56.  
  57.  
  58. global $paginated;
  59. $paginated .= "<center>Select a Page<br />";
  60.  
  61. if ($page == 1) {
  62. $paginated .= " FIRST PREV ";
  63. } else {
  64. $paginated .= " <a href='{$_SERVER['PHP_SELF']}?page=1'>FIRST</a> ";
  65. $prevpage = $page-1;
  66. $paginated .= " <a href='{$_SERVER['PHP_SELF']}?page=$prevpage'>PREV</a> ";
  67. }
  68. $paginated .= " ( Page $page of $lastpage ) ";
  69.  
  70. if ($page == $lastpage) {
  71. $paginated .= " NEXT LAST ";
  72. } else {
  73. $nextpage = $page+1;
  74. $paginated .= " <a href='{$_SERVER['PHP_SELF']}?page=$nextpage'>NEXT</a> ";
  75. $paginated .= " <a href='{$_SERVER['PHP_SELF']}?page=$lastpage'>LAST</a> ";
  76. }
  77.  
  78. $test = '';
  79. for($i = 0;$i < $result->RecordCount(); $i++){
  80. $file = $result->Fields("title");
  81. $description = $result->Fields("description");
  82. $date = $result->Fields("date");
  83.  
  84. $test .= '<table width="100%%" border="0">
  85. <tr>
  86. <td></td>
  87. </tr>
  88. </table>
  89.  
  90. <table cellpadding="2" cellspacing="1" border="0" align="center" width="100%" class="tbl_border_mem">
  91. <tr class="tbl_caption_mem">
  92. <td width="12%"><strong>Title</strong></td>
  93. <td width="73%"><strong>Description</strong></td>
  94. <td width="15%"><strong>Date Added</strong></td>
  95. </tr>
  96. <tr class="tbl_caption_mem">
  97. <td valign="top">'.$file.'</td>
  98. <td valign="top">'.$description.'</td>
  99. <td valign="top">'.$date.'</td>
  100. </tr>
  101. </table> <br />';
  102.  
  103. $result->movenext();
  104. }
  105. }
  106. $files = $test;
  107. DisplayTemplate($theme_path . "cp/data.html", "\$files,\$paginated,\$error_msg");
  108. }
  109.  
  110. /*===================================================
  111.   main
  112.   ===================================================*/
  113.  
  114. include "../application.php";
  115.  
  116. RunPreFilter(__FILE__);
  117.  
  118. ShowMyFiles();
  119.  
  120. RunPostFilter(__FILE__);
  121.  
  122. ?>

it produces the number of pages, but when user clicks on next, it goes to next page but blank screen. this is part of a dropdown menu and the form is passing select into this script. many thanks.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 20
Reputation: ploppy is an unknown quantity at this point 
Solved Threads: 0
ploppy ploppy is offline Offline
Newbie Poster

Re: pagination not displaying results

 
0
  #2
Oct 17th, 2007
can no-one offer any assistance? thanks
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: pagination not displaying results

 
0
  #3
Oct 17th, 2007
this might help, i never could test it.

  1. <?php
  2. function ShowMyFiles() {
  3.  
  4. // vars global configuration
  5. global $dbConn, $theme_path;
  6.  
  7. // vars messages
  8. global $msg;
  9. // vars template
  10. global $error_msg, $status, $files, $owner, $test, $paginated;
  11.  
  12. if ($err) {
  13. $error_msg = 'Custom error message';
  14. }
  15.  
  16. if(!isset($_GET['page'])){
  17. $page = 1;
  18. } else {
  19. $page = $_GET['page'];
  20. }
  21.  
  22. // get variable after selecting something from the dropdown with name 'chooser'
  23. $select = $_POST['select'];
  24.  
  25.  
  26. // if something has been chosen
  27. if (!empty($select)) {
  28.  
  29. // get the chosen value
  30. $chooser = $_POST['chooser'];
  31.  
  32. // Define the number of results per page
  33. $max_results = 10;
  34.  
  35. // Figure out the limit for the query based
  36. // on the current page number.
  37. $from = (($page * $max_results) - $max_results);
  38.  
  39. // get file listing
  40. // if everything successful create query
  41. // this selects all rows where the type is the one you chose in the dropdown
  42. // * means that it will select all columns, ie name and type as i said above
  43.  
  44. $sql = "SELECT title, description, date FROM idx_reslink WHERE category_id='$chooser' LIMIT $from, $max_results";
  45. $result = mysql_query($sql) or die(mysql_error());
  46.  
  47.  
  48. // Figure out the total number of results in DB:
  49. $total_results = mysql_num_rows($result);
  50.  
  51.  
  52. // Figure out the total number of pages. Always round up using ceil()
  53. $lastpage = $total_results / $max_results;
  54.  
  55.  
  56.  
  57. global $paginated;
  58. $paginated .= "<center>Select a Page<br />";
  59.  
  60. if ($page == 1) {
  61. $paginated .= " FIRST PREV ";
  62. } else {
  63. $paginated .= " <a href='{$_SERVER['PHP_SELF']}?page=1'>FIRST</a> ";
  64. $prevpage = $page-1;
  65. $paginated .= " <a href='{$_SERVER['PHP_SELF']}?page=$prevpage'>PREV</a> ";
  66. }
  67. $paginated .= " ( Page $page of $lastpage ) ";
  68.  
  69. if ($page == $lastpage) {
  70. $paginated .= " NEXT LAST ";
  71. } else {
  72. $nextpage = $page+1;
  73. $paginated .= " <a href='{$_SERVER['PHP_SELF']}?page=$nextpage'>NEXT</a> ";
  74. $paginated .= " <a href='{$_SERVER['PHP_SELF']}?page=$lastpage'>LAST</a> ";
  75. }
  76.  
  77. $test = '';
  78. while ($row = mysql_fetch_assoc($result)) {
  79. $file = $row['title'];
  80. $description = $row['description'];
  81. $date = $row['date'];
  82.  
  83. $test .= '<table width="100%%" border="0">
  84. <tr>
  85. <td></td>
  86. </tr>
  87. </table>
  88.  
  89. <table cellpadding="2" cellspacing="1" border="0" align="center" width="100%" class="tbl_border_mem">
  90. <tr class="tbl_caption_mem">
  91. <td width="12%"><strong>Title</strong></td>
  92. <td width="73%"><strong>Description</strong></td>
  93. <td width="15%"><strong>Date Added</strong></td>
  94. </tr>
  95. <tr class="tbl_caption_mem">
  96. <td valign="top">'.$file.'</td>
  97. <td valign="top">'.$description.'</td>
  98. <td valign="top">'.$date.'</td>
  99. </tr>
  100. </table> <br />';
  101.  
  102. $result->movenext();
  103. }
  104. }
  105. $files = $test;
  106. DisplayTemplate($theme_path . "cp/data.html", "\$files,\$paginated,\$error_msg");
  107. }
  108.  
  109. /*===================================================
  110.   main
  111.   ===================================================*/
  112.  
  113. include "../application.php";
  114.  
  115. RunPreFilter(__FILE__);
  116.  
  117. ShowMyFiles();
  118.  
  119. RunPostFilter(__FILE__);
  120.  
  121. ?>

Just tell me any errors and i can fix them
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 20
Reputation: ploppy is an unknown quantity at this point 
Solved Threads: 0
ploppy ploppy is offline Offline
Newbie Poster

Re: pagination not displaying results

 
0
  #4
Oct 18th, 2007
thank you ever so much for your help kkeith. however, i get this error:
  1. Fatal error: Call to a member function movenext() on a non-object in C:\wamp\www\public_html\cp\data.php on line 102
this line refers to this statement
  1. $result->movenext();
If i remove that statement, then the pagination only shows page 1of1 and no links. there should be links. there are over 700 entries that should be coming back.
Thanks for continuing help kkeith.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: pagination not displaying results

 
0
  #5
Oct 18th, 2007
well that line is referring to a function you did not post. if you know where it is post it. otherwise i will rewrite the code so it works. ill post it soon
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: pagination not displaying results

 
0
  #6
Oct 19th, 2007
i think i have solved your problem. i also remade the code without all the globals and template stuff.

Original Code Fixed (I think):

  1. <?php
  2. function ShowMyFiles() {
  3.  
  4. // vars global configuration
  5. global $dbConn, $theme_path;
  6.  
  7. // vars messages
  8. global $msg;
  9. // vars template
  10. global $error_msg, $status, $files, $owner, $test, $paginated;
  11.  
  12. if ($err) {
  13. $error_msg = 'Custom error message';
  14. }
  15.  
  16. if(!isset($_GET['page'])){
  17. $page = 1;
  18. } else {
  19. $page = $_GET['page'];
  20. }
  21.  
  22. // get variable after selecting something from the dropdown with name 'chooser'
  23. $select = $_POST['select'];
  24.  
  25.  
  26. // if something has been chosen
  27. if (!empty($select)) {
  28.  
  29. // get the chosen value
  30. $chooser = $_POST['chooser'];
  31.  
  32. // Define the number of results per page
  33. $max_results = 10;
  34.  
  35. // Figure out the limit for the query based
  36. // on the current page number.
  37. $from = (($page * $max_results) - $max_results);
  38.  
  39. // get file listing
  40. // if everything successful create query
  41. // this selects all rows where the type is the one you chose in the dropdown
  42. // * means that it will select all columns, ie name and type as i said above
  43.  
  44. $sql1 = "SELECT * FROM idx_reslink WHERE category_id = '" . $chooser . "'";
  45. $result1 = mysql_query($sql1);
  46.  
  47. $sql = "SELECT title, description, date FROM idx_reslink WHERE category_id='$chooser' LIMIT $from, $max_results";
  48. $result = mysql_query($sql) or die(mysql_error());
  49.  
  50.  
  51. // Figure out the total number of results in DB:
  52. $total_results = mysql_num_rows($result1);
  53.  
  54.  
  55. // Figure out the total number of pages. Always round up using ceil()
  56. $lastpage = $total_results / $max_results;
  57.  
  58.  
  59.  
  60. global $paginated;
  61. $paginated .= "<center>Select a Page<br />";
  62.  
  63. if ($page == 1) {
  64. $paginated .= " FIRST PREV ";
  65. } else {
  66. $paginated .= " <a href='{$_SERVER['PHP_SELF']}?page=1'>FIRST</a> ";
  67. $prevpage = $page-1;
  68. $paginated .= " <a href='{$_SERVER['PHP_SELF']}?page=$prevpage'>PREV</a> ";
  69. }
  70. $paginated .= " ( Page $page of $lastpage ) ";
  71.  
  72. if ($page == $lastpage) {
  73. $paginated .= " NEXT LAST ";
  74. } else {
  75. $nextpage = $page+1;
  76. $paginated .= " <a href='{$_SERVER['PHP_SELF']}?page=$nextpage'>NEXT</a> ";
  77. $paginated .= " <a href='{$_SERVER['PHP_SELF']}?page=$lastpage'>LAST</a> ";
  78. }
  79.  
  80. $test = '';
  81. while ($row = mysql_fetch_assoc($result)) {
  82. $file = $row['title'];
  83. $description = $row['description'];
  84. $date = $row['date'];
  85.  
  86. $test .= '<table width="100%%" border="0">
  87. <tr>
  88. <td></td>
  89. </tr>
  90. </table>
  91.  
  92. <table cellpadding="2" cellspacing="1" border="0" align="center" width="100%" class="tbl_border_mem">
  93. <tr class="tbl_caption_mem">
  94. <td width="12%"><strong>Title</strong></td>
  95. <td width="73%"><strong>Description</strong></td>
  96. <td width="15%"><strong>Date Added</strong></td>
  97. </tr>
  98. <tr class="tbl_caption_mem">
  99. <td valign="top">'.$file.'</td>
  100. <td valign="top">'.$description.'</td>
  101. <td valign="top">'.$date.'</td>
  102. </tr>
  103. </table> <br />';
  104.  
  105. }
  106. }
  107. $files = $test;
  108. DisplayTemplate($theme_path . "cp/data.html", "\$files,\$paginated,\$error_msg");
  109. }
  110.  
  111. /*===================================================
  112.   main
  113.   ===================================================*/
  114.  
  115. include "../application.php";
  116.  
  117. RunPreFilter(__FILE__);
  118.  
  119. ShowMyFiles();
  120.  
  121. RunPostFilter(__FILE__);
  122.  
  123. ?>

Here is the remake without all the extras:

All you have to do is fill in the mysql database connect stuff at the top of the script to make it work i hope

  1. <?php
  2.  
  3. function showFiles() {
  4.  
  5. $con = mysql_connect("localhost","username","password") or die('Couldn\'t connect to mysql');
  6.  
  7. mysql_select_db('db_name', $con) or die('Couldn\'t select database');
  8.  
  9. $page = $_GET['page'];
  10.  
  11. if (!isset($page) || $page == NULL) {
  12. $page = 1;
  13. }
  14. else {
  15. $page = $_GET['page'];
  16. }
  17.  
  18. if ($_REQUEST['select'] !== NULL) {
  19.  
  20. $chooser = $_REQUEST['chooser'];
  21. $num = 10;
  22. $lim = $page * $num;
  23. $lim = $lim - $num;
  24.  
  25. $sql = "SELECT * FROM idx_reslink WHERE category_id = '" . $chooser . "'";
  26. $query = mysql_query($sql);
  27. $tot = mysql_num_rows($query);
  28.  
  29. $sql = "SELECT title,description,date FROM idx_reslink WHERE category_id = '" . $chooser . "' LIMIT " . $lim . ", " . $num;
  30. $query = mysql_query($sql);
  31. $lpage = ($tot/$num);
  32. $thispage = $_SERVER['PHP_SELF'];
  33.  
  34. if($page > 1) {
  35. $prev = $page - 1;
  36. $last = '<a href="' . $thispage . '?page=1">First</a> <a href="' . $thispage . '?page=' . $prev . '">PREV</a>';
  37. }
  38. if ($lpage > $page) {
  39. $go = $page + 1;
  40. $next = '<a href="' . $thispage . '?page=' . $go . '">NEXT</a> <a href="' . $thispage . '?page=' . $lpage . '">Last</a>';
  41. }
  42.  
  43. echo '<table cellpadding="2" cellspacing="1" border="0" align="center" width="100%" class="tbl_border_mem">';
  44. echo '<tr><td width="12%"><strong>Title</strong></td><td width="73%"><strong>Description</strong></td><td width="15%"><strong>Date Added</strong></td></tr>';
  45.  
  46. while ($row = mysql_fetch_assoc($query)) {
  47.  
  48. $title = $row['title'];
  49. $description = $row['description'];
  50. $date = $row['date'];
  51.  
  52. echo '<tr><td valign="top">' . $title . '</td><td valign="top">' . $description . '</td><td valign="top">' . $date . '</td></tr>';
  53.  
  54. }
  55.  
  56. echo '<tr><td>' . $last . '</td><td colspan="2" align="right">' . $next . '</td></tr>';
  57. echo '</table>';
  58.  
  59. }
  60.  
  61. mysql_close($con);
  62.  
  63. }
  64.  
  65. showFiles();
  66.  
  67. ?>
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 20
Reputation: ploppy is an unknown quantity at this point 
Solved Threads: 0
ploppy ploppy is offline Offline
Newbie Poster

Re: pagination not displaying results

 
0
  #7
Oct 19th, 2007
kkeith. neither version work. both display pagination but when next is clicked, blank page. the function that the command $result->movenext(); is this:

  1. function MoveNext() {
  2. if ($row = mysql_fetch_assoc($this->resultset)) {
  3. $this->current_row = $row;
  4. $this->EOF = false;
  5. return true;
  6. }
  7. else {
  8. $this->EOF = true;
  9. return false;
  10. }
  11. }]

i need to work within the template system of the first script because it is an integral part of the site in terms layout etc. if it would help, i can post the whole of the db.class file. thank you ever so much in trying to get this script to work and for your valuable time and effort. cheers
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: pagination not displaying results

 
0
  #8
Oct 19th, 2007
they both worked for me. i don't know what going on. i set up the mysql tables and everthing on my server. it displayed just fine. what would help me out if you posted your entire class. this would make it easier to see everything else going on.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 20
Reputation: ploppy is an unknown quantity at this point 
Solved Threads: 0
ploppy ploppy is offline Offline
Newbie Poster

Re: pagination not displaying results

 
0
  #9
Oct 19th, 2007
db.class.php

  1. <?
  2.  
  3. class DB_Connection {
  4. var $conn = null;
  5. var $debug = false;
  6. var $num_query = 0;
  7. var $error_msg = "";
  8. var $affected_rows = 0;
  9.  
  10. function DB_Connection($host, $username, $pwd, $db) {
  11. $this->Connect($host, $username, $pwd, $db);
  12. }
  13.  
  14. function Connect($host, $username, $pwd, $db) {
  15. global $db_use_persistent;
  16. if ($db_use_persistent) {
  17. $this->conn = mysql_pconnect($host, $username, $pwd);
  18. }
  19. else {
  20. $this->conn = mysql_connect($host, $username, $pwd);
  21. }
  22. mysql_select_db($db, $this->conn);
  23. }
  24.  
  25. function Execute($query) {
  26. $query = trim($query);
  27. $this->num_query++;
  28. if ($this->debug) {
  29. static $mysql_query_number;
  30. static $mysql_query_time;
  31. $mysql_query_number++;
  32. $time_start = (float) array_sum(explode(' ', microtime()));
  33. }
  34. $result = @mysql_query($query, $this->conn);
  35. if ($this->debug) {
  36. $time_end = (float) array_sum(explode(' ', microtime()));
  37. $time = $time_end - $time_start;
  38. $time = sprintf("%01.4f", $time);
  39. $mysql_query_time += $time;
  40. $mysql_query_time = sprintf("%01.3f", $mysql_query_time);
  41. if ($time > 1) {
  42. $time = "<b>$time [slow query]</b>";
  43. }
  44. if (preg_match('/^select/i', $query)) {
  45. $num_rows = @mysql_num_rows($result);
  46. echo "<table width='100%' border='1' cellspacing='1'><tr valign='top'><td width='70'>QUERY #$mysql_query_number: </td><td>$query (result : $num_rows, time : $time)</td><td align='right' width='30'>$mysql_query_time</td></tr></table>";
  47. }
  48. else {
  49. echo "<table width='100%' border='1' cellspacing='1><tr valign='top'><td width='70'>QUERY #$mysql_query_number: </td><td>$query (time : $time)</td></td><td align='right' width='30'>$mysql_query_time</td></tr></table>";
  50. }
  51. if (mysql_error()) {
  52. echo "<table width='100%' border='1' cellspacing='1><tr valign='top'><td width='70'><font color='red'><b>ERROR : </b></font></td><td><font color='red'><b>".mysql_error()."</b></font></td><td align='right' width='30'>$mysql_query_time</td></tr></table>";
  53. }
  54. }
  55. $this->error_msg = mysql_error();
  56. if ($this->error_msg) {
  57. return false;
  58. }
  59. else {
  60. if (preg_match("/^update|insert|delete/msi", $query)) {
  61. $this->affected_rows = @mysql_affected_rows($this->conn);
  62. return new DB_Resultset_empty();
  63. }
  64. else {
  65. return new DB_Resultset($result, $query);
  66. }
  67. }
  68. }
  69.  
  70. function PageExecute($query, $pg_which, $pg_size) {
  71. if (!$pg_which) {
  72. $pg_which = 1;
  73. }
  74. $query_total = $query;
  75. if (!preg_match('/group by/msi', $query_total)) {
  76. $query_total = preg_replace("|select(.*?)from|ms", "select count(*) as c from", $query_total);
  77. }
  78. $result = $this->Execute($query_total);
  79. if (preg_match('/group by/msi', $query_total)) {
  80. $num_rows = $result->RecordCount();
  81. }
  82. else {
  83. $num_rows = ($result->Fields('c')) ? $result->Fields('c') : 0;
  84. }
  85. $start = ($pg_which - 1) * $pg_size;
  86. $query = $query . " limit $start, $pg_size";
  87. $result->Close();
  88. $result = $this->Execute($query);
  89. $result->num_rows = $num_rows;
  90. return $result;
  91. }
  92.  
  93. function InsertID() {
  94. return @mysql_insert_id($this->conn);
  95. }
  96.  
  97. function Close() {
  98. return true;
  99. }
  100.  
  101. function FetchArray($query) {
  102. $result = $this->Execute($query);
  103. $arr = array ();
  104. while ($row = $result->FetchRow()) {
  105. $arr[] = $row;
  106. }
  107. $result->Close();
  108. return $arr;
  109. }
  110.  
  111. function FetchOne($query) {
  112. $result = $this->Execute($query . ' limit 1');
  113. $row = $result->FetchRow();
  114. $result->Close();
  115. return $row;
  116. }
  117.  
  118. function Lookup($field, $table, $where) {
  119. $result = $this->Execute("select $field from $table where $where limit 1");
  120. $value = $result->Fields($field);
  121. $result->Close();
  122. return $value;
  123. }
  124.  
  125. function CountQuery() {
  126. return $this->num_query;
  127. }
  128.  
  129. function ErrorMsg() {
  130. return $this->error_msg;
  131. }
  132.  
  133. function AffectedRows() {
  134. return $this->affected_rows;
  135. }
  136. }
  137.  
  138. class DB_Resultset {
  139. var $resultset = null;
  140. var $num_rows = null;
  141. var $num_field = null;
  142. var $current_row = null;
  143. var $EOF = true;
  144. var $query = null;
  145.  
  146. function DB_Resultset(&$resultset, $query = '') {
  147. $this->resultset = $resultset;
  148. $this->query = $query;
  149. if (preg_match('/^select|show|describe|explain/msi', $query)) {
  150. $this->MoveNext();
  151. }
  152. }
  153.  
  154. function RecordCount() {
  155. if (is_null($this->num_rows)) {
  156. $this->num_rows = @mysql_num_rows($this->resultset);
  157. }
  158. return $this->num_rows;
  159. }
  160.  
  161. function FieldCount() {
  162. if (is_null($this->num_field)) {
  163. $this->num_field = mysql_num_fields($this->resultset);
  164. }
  165. return $this->num_field;
  166. }
  167.  
  168. function FetchField($offset) {
  169. $field = mysql_fetch_field($this->resultset, $offset);
  170. $field->max_length = mysql_field_len($this->resultset, $offset);
  171. return $field;
  172. }
  173.  
  174. function MetaType($field_type) {
  175. switch($field_type) {
  176. case preg_match('/char/i', $field_type):
  177. return 'C';
  178. case preg_match('/int|float|double/i', $field_type):
  179. return 'I';
  180. case preg_match('/text/i', $field_type):
  181. return 'X';
  182. case preg_match('/blob/', $field_type):
  183. return 'B';
  184. default:
  185. return '';
  186. }
  187. }
  188.  
  189. function Move($offset) {
  190. if (@mysql_data_seek($this->resultset, $offset)) {
  191. return $this->MoveNext();
  192. }
  193. else {
  194. return false;
  195. }
  196. }
  197.  
  198. function MoveFirst() {
  199. return $this->Move(0);
  200. }
  201.  
  202. function MoveLast() {
  203. return $this->Move($this->num_rows - 1);
  204. }
  205.  
  206. function MoveNext() {
  207. if ($row = mysql_fetch_assoc($this->resultset)) {
  208. $this->current_row = $row;
  209. $this->EOF = false;
  210. return true;
  211. }
  212. else {
  213. $this->EOF = true;
  214. return false;
  215. }
  216. }
  217.  
  218. function Fields($name) {
  219. return $this->current_row[$name];
  220. }
  221.  
  222. function FetchRow() {
  223. if (!$this->EOF) {
  224. $row = $this->current_row;
  225. $this->MoveNext();
  226. return $row;
  227. }
  228. else {
  229. return false;
  230. }
  231. }
  232.  
  233. function Close() {
  234. if ($this->resultset) {
  235. mysql_free_result($this->resultset);
  236. }
  237. }
  238. }
  239.  
  240. class DB_Resultset_empty {
  241. var $resultset = null;
  242. var $num_rows = null;
  243. var $num_field = null;
  244. var $current_row = null;
  245. var $EOF = true;
  246. var $query = null;
  247.  
  248. function DB_Resultset() {
  249. return true;
  250. }
  251.  
  252. function RecordCount() {
  253. return 0;
  254. }
  255.  
  256. function FieldCount() {
  257. return 0;
  258. }
  259.  
  260. function FetchField($offset) {
  261. return false;
  262. }
  263.  
  264. function MetaType($field_type) {
  265. return false;
  266. }
  267.  
  268. function Move($offset) {
  269. return false;
  270. }
  271.  
  272. function MoveFirst() {
  273. return false;
  274. }
  275.  
  276. function MoveLast() {
  277. return false;
  278. }
  279.  
  280. function MoveNext() {
  281. return false;
  282. }
  283.  
  284. function Fields($name) {
  285. return false;
  286. }
  287.  
  288. function FetchRow() {
  289. return false;
  290. }
  291.  
  292. function Close() {
  293. return true;
  294. }
  295. }
  296.  
  297.  
  298. $ADODB_SESS_CONN = null;
  299. $ADODB_SESS_MD5 = false;
  300.  
  301. class DB_Session {
  302.  
  303. function Open($save_path, $session_name) {
  304. global $ADODB_SESS_CONN, $dbServer, $dbHostname, $dbUsername, $dbPassword, $dbName;
  305. //echo "open<br>";
  306. if (is_null($ADODB_SESS_CONN)) {
  307. $ADODB_SESS_CONN = new DB_Connection($dbHostname, $dbUsername, $dbPassword, $dbName);
  308. }
  309. return true;
  310. }
  311.  
  312. function Close() {
  313. global $ADODB_SESS_CONN;
  314. //echo "close<br>";
  315. if (!is_null($ADODB_SESS_CONN)) {
  316. $ADODB_SESS_CONN->Close();
  317. }
  318. return true;
  319. }
  320.  
  321. function Read($key) {
  322. global $ADODB_SESS_CONN, $ADODB_SESS_MD5;
  323. //echo "read<br>";
  324. $data = '';
  325. if ($ADODB_SESS_CONN) {
  326. $query = "select data from idx_sessions where sesskey = '$key' AND expiry >= " . time();
  327. $result = $ADODB_SESS_CONN->Execute($query);
  328. if ($result->RecordCount()) {
  329. $data = rawurldecode($result->Fields('data'));
  330. }
  331. $ADODB_SESS_MD5 = md5($data);
  332. $result->Close();
  333. }
  334. return $data;
  335. }
  336.  
  337. function Write($key, $data) {
  338. global $ADODB_SESS_CONN, $ADODB_SESS_MD5;
  339. //echo "write<br>";
  340. if ($ADODB_SESS_CONN) {
  341. $lifetime = ini_get('session.gc_maxlifetime');
  342. if ($lifetime <= 1) {
  343. $lifetime = 1440;
  344. }
  345. $expiry = time() + $lifetime;
  346. if ($ADODB_SESS_MD5 !== false && $ADODB_SESS_MD5 == md5($data)) {
  347. $query = "update idx_sessions set expiry = '$expiry' where sesskey = '$key'";
  348. }
  349. else {
  350. $data = rawurlencode($data);
  351. $query = "replace into idx_sessions (sesskey, expiry, data) values ('$key', '$expiry', '$data')";
  352. }
  353. $ADODB_SESS_CONN->Execute($query);
  354. }
  355. return true;
  356. }
  357.  
  358. function Destroy($key) {
  359. global $ADODB_SESS_CONN;
  360. //echo "detroy<br>";
  361. if ($ADODB_SESS_CONN) {
  362. $query = "delete from idx_sessions where sesskey = '$key'";
  363. $ADODB_SESS_CONN->Execute($query);
  364. }
  365. return true;
  366. }
  367.  
  368. function GC($maxlifetime) {
  369. global $ADODB_SESS_CONN;
  370. //echo "gc<br>";
  371. if ($ADODB_SESS_CONN) {
  372. $query = "delete from idx_sessions where expiry < ".time();
  373. $ADODB_SESS_CONN->Execute($query);
  374. $query = "optimize table idx_sessions";
  375. $ADODB_SESS_CONN->Execute($query);
  376. }
  377. return true;
  378. }
  379.  
  380. function Init() {
  381. //echo "init<br>";
  382. session_module_name('user');
  383. session_set_save_handler(
  384. array('DB_Session', 'Open'),
  385. array('DB_Session', 'Close'),
  386. array('DB_Session', 'Read'),
  387. array('DB_Session', 'Write'),
  388. array('DB_Session', 'Destroy'),
  389. array('DB_Session', 'GC')
  390. );
  391. }
  392. }
  393.  
  394. DB_Session::Init();
  395.  
  396. ?>

pagination.class.php

  1. <?php
  2.  
  3. class navigator {
  4. var $pg_size = 10;
  5. var $pg_which = 1;
  6. var $cp_size = 10;
  7. var $rec_count = 0;
  8. var $rec_start = 0;
  9. var $more_param = "";
  10. var $href = "";
  11. var $page_file = "";
  12. var $page_title = "";
  13.  
  14. var $page_text = "Pages";
  15. var $first_text = "[First]";
  16. var $last_text = "[Last]";
  17. var $prev_text = "[Prev]";
  18. var $next_text = "[Next]";
  19.  
  20. var $active_link_color = "";
  21. var $disable_link_color = "gray";
  22.  
  23. function init() {
  24. global $lang;
  25. $this->rec_start = ($this->pg_which - 1) * $this->pg_size;
  26. if ($lang['nav_page']) {
  27. $this->page_text = $lang['nav_page'];
  28. }
  29. if ($lang['nav_first']) {
  30. $this->first_text = $lang['nav_first'];
  31. }
  32. if ($lang['nav_last']) {
  33. $this->last_text = $lang['nav_last'];
  34. }
  35. if ($lang['nav_prev']) {
  36. $this->prev_text = $lang['nav_prev'];
  37. }
  38. if ($lang['nav_next']) {
  39. $this->next_text = $lang['nav_next'];
  40. }
  41. }
  42.  
  43. function print_all() {
  44. $length = $this->rec_count;
  45. if ($length <= $this->pg_size) {
  46. return;
  47. }
  48.  
  49. if (!is_numeric($this->pg_which)) {
  50. $this->pg_which = 1;
  51. }
  52.  
  53. $pref = (strpos($this->href, "?") === FALSE) ? "?" : "&";
  54. $radius = floor($this->cp_size / 2 * $this->pg_size);
  55. $offset = ($this->pg_which - 1) * $this->pg_size;
  56. if ($offset < $radius) {
  57. $start = 0;
  58. }
  59. elseif ($offset <= $length - $radius) {
  60. $start = $offset - $radius;
  61. }
  62. else {
  63. $start = (floor($length / $this->pg_size) - $this->cp_size) * $this->pg_size + $this->pg_size;
  64. if ($start < 0) {
  65. $start = $this->pg_size;
  66. }
  67. }
  68.  
  69. $out = "";
  70. if ($offset > 0) {
  71. if ($start > 1) {
  72. $out .= "<a href=\"" . $this->href . $pref . "pg_which=1$this->more_param\" style=\"color: $this->active_link_color\">". $this->first_text ."</a>\n";
  73. }
  74. $out .= "<a href=\"" . $this->href . $pref . "pg_which=" . ($this->pg_which - 1) . $this->more_param . "\" style=\"color: $this->active_link_color\">". $this->prev_text ."</a>\n";
  75. }
  76.  
  77. for ($i = $start; (($i < $length) && ($i < $start + $this->cp_size * $this->pg_size)); $i += $this->pg_size) {
  78. if ($i == $offset) {
  79. $out .= "<font color=\"$this->disable_link_color\"><b>" . ($i / $this->pg_size + 1) . "</b></font>\n";
  80. }
  81. else {
  82. $out .= "<a href=\"" . $this->href . $pref . "pg_which=" . ($i / $this->pg_size + 1) . $this->more_param . "\" style=\"color: $this->active_link_color\">" . ($i / $this->pg_size + 1) . "</a>\n";
  83. }
  84. }
  85.  
  86. if ($offset < $length - $this->pg_size) {
  87. $out .= "<a href=\"" . $this->href . $pref . "pg_which=" . ($this->pg_which + 1) . $this->more_param . "\" style=\"color: $this->active_link_color\">". $this->next_text ."</a>\n";
  88. if ((ceil($length/$this->pg_size) - 1) * $this->pg_size >= $i) {
  89. $out .= "<a href=\"" . $this->href . $pref . "pg_which=" . ceil($length/$this->pg_size) . $this->more_param . "\" style=\"color: $this->active_link_color\">". $this->last_text ."</a>\n";
  90. }
  91. }
  92.  
  93. if (GetModRewriteStatus() == '1') {
  94. $this->apply_seo($out);
  95. }
  96.  
  97. $out = $this->page_text . ": " . $out;
  98.  
  99. return $out;
  100.  
  101. }
  102.  
  103. function apply_seo(&$out) {
  104. if ($this->page_file == "browse") {
  105. $src[] = "|\"browse.php\?pg_which=(\w*?)&cat=(\w*?)\"|mse";
  106. $replacement[] = "\$this->apply_browse_seo('\\1', '\\2')";
  107. }
  108.  
  109. if (is_array($src)) {
  110. $out = preg_replace($src, $replacement, $out);
  111. }
  112. }
  113.  
  114. function apply_browse_seo($page, $cat) {
  115. $page_title = SEOReplace($this->page_title);
  116. $mod_rewrite_pattern = GetModRewritePatternCategory();
  117. if (strpos($mod_rewrite_pattern, '{$cat_path}') === FALSE) {
  118. $mod_rewrite_pattern = str_replace('{$cat_name}', $page_title, $mod_rewrite_pattern);
  119. $mod_rewrite_pattern = str_replace('{$cat_id}', $cat, $mod_rewrite_pattern);
  120. $mod_rewrite_pattern = str_replace('{$page}', $page, $mod_rewrite_pattern);
  121. $out = strtolower($mod_rewrite_pattern);
  122. }
  123. else {
  124. $page_text = substr(strrchr($mod_rewrite_pattern, '/'), 1);
  125. $out = $_SERVER['REQUEST_URI'];
  126. if (strpos($out, '.html') !== FALSE) {
  127. $outs = explode('/', $out);
  128. unset($outs[@count($outs) - 1]);
  129. $out = implode('/', $outs) . '/';
  130. }
  131. if ($page > 1) {
  132. if (substr($out, -1) != '/') {
  133. $out .= '/';
  134. }
  135. $out .= str_replace('{$page}', $page, $page_text);
  136. }
  137. $out = "\"$out\"";
  138. }
  139. return $out;
  140. }
  141.  
  142. }
  143.  
  144. ?>

thank you ever so much kkeith. cheers
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: pagination not displaying results

 
0
  #10
Oct 20th, 2007
i guess i should of looked at your code and problem more. the reason the results are not displaying is that when the page is redirected the post data is gone meaning that there is no chooser variable. i suggest passing this info with the url. if i need to do this i will just let me know. sorry it took me so long
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC