General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 9th, 2003, 11:46 AM
worchyld worchyld is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 13 worchyld User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy Getting Joe O'Donnell's Paging Class to Page

I recently downloaded the code for the paging class from:
http://www.devarticles.com/art/1/110/6

The code isn't half bad, and it appears to work - however there is one problem - it doesn't page at all.

I haven't changed the code at all (except where I need to connect to the database) - the table I am trying to page has well over 100 records in it - but Joe O' Donnell's paging class always returns the first 10 records.

I was hoping to adapt the paging code so that I can do ordering on a row with more advanced features.

I hope that someone can help on this subject. Thanks.

Reply With Quote
  #2  
Old July 9th, 2003, 01:54 PM
avit avit is offline
Not Yet Perfect
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: Squamish, BC
Posts: 111 avit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to avit
Your symptoms indicate that recnav's ShowRecs() function isn't receiving a value for $Page and it defaults to 1. How is the page number being passed in?

Reply With Quote
  #3  
Old July 17th, 2003, 07:29 AM
worchyld worchyld is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 13 worchyld User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Its the same way that O'Donnell

Its the same code as O'Donell's, I haven't changed anything - except the rows.

If someone has got this to work, any chance of posting it, that way I can compare what I'm doing wrong.

Reply With Quote
  #4  
Old July 17th, 2003, 07:27 PM
avit avit is offline
Not Yet Perfect
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: Squamish, BC
Posts: 111 avit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to avit
Instead of this:

PHP Code:
global $HTTP_GET_VARS
$page $HTTP_GET_VARS["page"]; 


Try this:

PHP Code:
 $page $_GET['page']; 

Reply With Quote
  #5  
Old July 17th, 2003, 07:48 PM
DDDooGGG DDDooGGG is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Melbourne, Australia
Posts: 97 DDDooGGG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 33 sec
Reputation Power: 6
That didnt work
__________________
regards,


Fulton

Reply With Quote
  #6  
Old July 17th, 2003, 08:19 PM
avit avit is offline
Not Yet Perfect
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: Squamish, BC
Posts: 111 avit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to avit
For what it's worth, I use a stripped-down version of that class, and it does work.

It's hard to guess what's wrong without seeing your code.

Echo the value of $page before you call RecNav to see if it actually has a value.

...And show us some code...

Reply With Quote
  #7  
Old July 17th, 2003, 09:04 PM
DDDooGGG DDDooGGG is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Melbourne, Australia
Posts: 97 DDDooGGG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 33 sec
Reputation Power: 6
i thought maybe it was case sensitive as on the index page they have:
PHP Code:
global $_GET

$page $_GET["page"];  <---lowercase p 


in the class.recnav.php is as follows:
PHP Code:
if($Page <= 1)
        {
          
$Page 1; <---UNPPERCASE P
          $query 
$this->__query " LIMIT 0, " $this->__recsPerPage;
        } 


i changed these but still didnt work.

Reply With Quote
  #8  
Old July 17th, 2003, 09:16 PM
avit avit is offline
Not Yet Perfect
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: Squamish, BC
Posts: 111 avit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to avit
The $Page variable in RecNav is local to that function only, so as long as it's consistent in there it will be fine.

Do you get any output from echo $page; when you insert that into your code?

Does your next page link have a ?page=2 tacked on the end when seen in your browser?

Reply With Quote
  #9  
Old July 18th, 2003, 11:17 PM
DDDooGGG DDDooGGG is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Melbourne, Australia
Posts: 97 DDDooGGG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 33 sec
Reputation Power: 6
Hi
Where the Next and Previous pages are supposed to be displayed on the webpage, all i can see is the word "Pages". I DON'T see "Previous | 1 | 2 | Next", which is what i thought i would see or at least something similiar.

hope this cleaers up my last post.

Last edited by DDDooGGG : July 20th, 2003 at 09:24 PM.

Reply With Quote
  #10  
Old July 20th, 2003, 02:12 PM
avit avit is offline
Not Yet Perfect
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: Squamish, BC
Posts: 111 avit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to avit
well, how come?

Come on now, you're not giving us very much to go on.

Reply With Quote
  #11  
Old July 21st, 2003, 03:42 AM
worchyld worchyld is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 13 worchyld User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Sorry, been very busy

Sorry, I've been very busy over the past few days. Here is the code below:

You will need to change the mysql bits as needed

PHP Code:
<?php
// paging example
?>
<html>
<head> 
<title> Recordset Paging Example </title> 
</head> 
<body bgcolor="#FFFFFF"> 
<?php 
require("class.pager.php"); 

if (!empty(
$_GET)) {
    
extract($_GET);
} else if (!empty(
$HTTP_GET_VARS)) {
    
extract($HTTP_GET_VARS);
}

if (!empty(
$_POST)) {
    
extract($_POST);
} else if (!empty(
$HTTP_POST_VARS)) {
    
extract($HTTP_POST_VARS);
}

$bDebug false;

if(
$bDebug) {
    
error_reporting(E_ALL);
} else {
    
error_reporting(E_ERROR E_PARSE);
}

if (isset(
$HTTP_GET_VARS['page'])) {
    
$Page $HTTP_GET_VARS["page"]; 
} else {
    
$Page 1;
}

$headerTemplate "<h2>Log File</h2>"
$headerTemplate .= "<ul>"
$bodyTemplate "<li><b><| row1 |>:</b> <| row4 |></li>"
$footerTemplate "</ul>"

$mysqlhost "";
$mysqlroot "";
$mysqlpw "";
$db2use "";

$s mysql_connect($mysqlhost$mysqlroot$mysqlpw); 
$d mysql_select_db($db2use$s); 
$r = new RecNav($s"SELECT * FROM TABLE ORDER BY date ASC"$bodyTemplate$headerTemplate$footerTemplate10);

echo 
$page;

echo 
$r->ShowRecs($Page); 
?>

</body> 
</html>



PHP Code:
// class.pager.php file

  // Default number of records
  
define("DEFAULT_NUM_RECS"10);
  
define("DEFAULT_TEMPLATE_HEADER""<table width='100%' cellspacing='0' cellpadding='0' border='0'><tr><td width='10%' height='21' bgcolor='black' align='center'><font color='white' face='verdana' size='1'><b>Id</b></font></td><td width='80%' height='21' bgcolor='black'><font color='white' face='verdana' size='1'><b>Description</b></font></td><td width='10%' height='21' bgcolor='black' align='center'><font color='white' face='verdana' size='1'><b>Price</b></font></td></tr>");
  
define("DEFAULT_TEMPLATE""<tr><td width='10%' height='21' align='center'><font face='verdana' size='1' color='darkblue'><b><| row0 |></b></font></td><td width='80%' height='21'><font face='verdana' size='1' color='black'><| row1 |></font></td><td width='10%' height='21'><font face='verdana' size='1' color='red'>$<| row2 |></font></td></tr>");
  
define("DEFAULT_TEMPLATE_FOOTER""</table>");

  class 
RecNav
  
{
    function 
RecNav(&$LinkIdentifier$Query$Template=DEFAULT_TEMPLATE$TemplateHeader=DEFAULT_TEMPLATE_HEADER$TemplateFooter=DEFAULT_TEMPLATE_FOOTER$RecsPerPage=DEFAULT_NUM_RECS)
    {
      
// Validate constructor parameters
      
if(!@mysql_query("SELECT 1"$LinkIdentifier))
      { die(
"MYSQL link identifier is invalid"); }
      else
      {
        
$this->__linkId $LinkIdentifier;
      }

      if(!
ereg("^SELECT"$Query))
        { die(
"Invalid query: query must start with 'SELECT'"); }

      else
        { 
$this->__query $Query; }

      if(
$Template == "")
        { 
$this->__template DEFAULT_TEMPLATE; }
      else
        { 
$this->__template $Template; }

      if(
$TemplateHeader == "")
        { 
$this->__templateHeader DEFAULT_TEMPLATE_HEADER; }
      else
        { 
$this->__templateHeader $TemplateHeader; }

      if(
$TemplateFooter == "")
        { 
$this->__templateFooter DEFAULT_TEMPLATE_FOOTER; }
      else
        { 
$this->__templateFooter $TemplateFooter; }

      if(!
is_numeric($RecsPerPage) || $RecsPerPage 1)
        { 
$this->__recsPerPage DEFAULT_NUM_RECS; }
      else
        { 
$this->__recsPerPage $RecsPerPage; }
    }

    function 
ShowRecs($Page)
    {
      
// Using the classes variables and the $Page variable,
      // the ShowRecs function will query the database and
      // return the records based on the $__template variable.

      
$finalOutput $this->__templateHeader;

      if(
$Page <= 1)
        {
          
$Page 1;
          
$query $this->__query " LIMIT 0, " $this->__recsPerPage;
        }
      else
        { 
$query $this->__query " LIMIT " . (($Page-1) * $this->__recsPerPage) . ", " $this->__recsPerPage; }

      
$result mysql_query($query);
      
$hasRecords mysql_num_rows($result) == false true;

      if(
$hasRecords)
      {
        
// At least one records returned from the query
        
while($row mysql_fetch_row($result))
        {
          
$newRow $this->__template;

          for(
$i 0$i mysql_num_fields($result); $i++)
           { 
$newRow str_replace("<| row" $i " |>"$row[$i], $newRow); }

          
$finalOutput .= $newRow;
        }
      }
      else
      {
        
// No records returned from the query
        
$newRow $this->__template;
        
$newRow str_replace("<| row0 |>""No records found"$newRow);

        
// Replace all template tags with &nbsp;
        
$newRow ereg_replace("<| row[0-9] |>""&nbsp;"$newRow);

        
$finalOutput .= $newRow;
      }

      
$finalOutput .= $this->__templateFooter;

      
// Build the recordset paging links
      
$numTotalRecs mysql_num_rows(mysql_query($this->__query));
      
$numPages ceil($numTotalRecs $this->__recsPerPage);
      
$nav "";

      
// Can we have a link to the previous page?
      
if($Page 1)
        
$nav .= "<a href='$PHP_SELF?page=" . ($Page-1) . "'><< Prev</a> |";

      for(
$i 1$i $numPages+1$i++)
      {
        if(
$Page == $i)
        {
          
// Bold the page and dont make it a link
          
$nav .= " <b>$i</b> |";
        }
        else
        {
          
// Link the page
          
$nav .= " <a href='$PHP_SELF?page=$i'>$i</a> |";
        }
      }

      
// Can we have a link to the next page?
      
if($Page $numPages)
        
$nav .= " <a href='$PHP_SELF?page=" . ($Page+1) . "'>Next >></a>";

      
// Strip the trailing pipe if there is one
      
$nav ereg_replace("|$"""$nav);

      
$finalOutput .= "<div align='right'><font face='verdana' size='1'><br>Pages: $nav</font></div>";

      return 
$finalOutput;
    }

    var 
$__linkId;
    var 
$__dbType;
    var 
$__query;
    var 
$__template;
    var 
$__templateHeader;
    var 
$__templateFooter;
    var 
$__recsPerPage;