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, 10:46 AM
worchyld worchyld is offline
Registered User
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, 12: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: 16
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, 06:29 AM
worchyld worchyld is offline
Registered User
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, 06: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: 16
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, 06: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: 16
That didnt work
__________________
regards,


Fulton

Reply With Quote
  #6  
Old July 17th, 2003, 07: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: 16
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, 08: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: 16
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, 08: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: 16
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, 10: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: 16
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 08:24 PM.

Reply With Quote
  #10  
Old July 20th, 2003, 01: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: 16
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, 02:42 AM
worchyld worchyld is offline
Registered User
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;

  } 

Reply With Quote
  #12  
Old July 21st, 2003, 03:34 AM
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: 16
Send a message via ICQ to avit
Here's what I see:

PHP Code:
 echo*$r->ShowRecs($Page); 


Should have a lowercase $page

The uppercase $Page is OK within the class.recnav file, since that's local to the ShowRecs method.

Reply With Quote
  #13  
Old July 21st, 2003, 06:23 AM
worchyld worchyld is offline
Registered User
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 Didn't make any difference

Unfortuently that didn't work either. I think the error is in the class.

I do get this error though:

Quote:
Warning: REG_EMPTY in class.pager.php on line 122


PHP Code:
<?php
// pulls in the class
require("class.pager.php"); 

$page $HTTP_GET_VARS["page"]; 

$headerTemplate "<h2>Log File</h2>"

$headerTemplate .= "<ul>"
$bodyTemplate "<li><b><| row1 |>:</b> <| row2 |></li>"
$footerTemplate "</ul>"

$s mysql_connect("yourhose""yourusername""yourpw"); 
$d mysql_select_db("yourdb"$s); 

$r = new RecNav($s"SELECT *  FROM TABLE ORDER BY date DESC"$bodyTemplate$headerTemplate$footerTemplate10);

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


PHP Code:
<?php
// class
<?php

  
// 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;

  }
?>

Reply With Quote
  #14  
Old July 21st, 2003, 01:57 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: 16
Send a message via ICQ to avit
OK, I've got it. Replace this block:
PHP Code:
 ******// 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); 

With this:
PHP Code:
 ******// Strip the trailing pipe if there is one
******$nav*=*ereg_replace("\\|$",*"",*$nav);

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


The problem(s):

ereg_replace had an unbounded OR, which should have been an escaped pipe character.

Was: "|$" (empty string or end of string)
Changed to: "\|$" (pipe character followed by end of string)

Also, that ereg to remove the trailing pipe should come before the Next link is tagged on to the end of it (otherwise it's pointless).

Reply With Quote
  #15  
Old July 22nd, 2003, 03:22 AM
worchyld worchyld is offline
Registered User
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
Yey!

Hurrah! At last it works - thanks a lot for your help, it now has the "< Prev | 1 | 2 | 3" thing, but now I want to know how to limit this to say "10".

This is because it goes "< Prev | 1 | 2 | 3 ... all the way up to 61" - how do I make it stop at say 10 (but still allowing me to obviousily go to page 61.

Reply With Quote
  #16  
Old July 22nd, 2003, 04:04 AM
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: 16
Send a message via ICQ to avit
I have a function that returns a list centered on the current page (length is a parameter). Let me know if that's how you want it to work and I will post it for you tomorrow.

Reply With Quote
  #17  
Old July 22nd, 2003, 04:13 AM
worchyld worchyld is offline
Registered User
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
This is the problem

This image should show whats happening...



At the bottom it shows "< Prev | 1 | 2....all the way to 61" I want to prevent this, mainly because it sucks.

Reply With Quote
  #18  
Old July 22nd, 2003, 03:46 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: 16
Send a message via ICQ to avit
Add this function to your class and use it to generate your list of links between your Prev and Next. It takes an integer as a parameter and creates a list of that length, centered over the current page.

That is, if you have 61 pages and you are on page 22 you will get 17...27 as links. (Assuming a length of 10.) On page 1 you will get 1...10 and on page 61 you will get 51...61

PHP Code:
function get_scroll($length) {
    
$start $this->current floor($length/2);
    
$end   $this->current floor($length/2) - + ($length%2);
    if (
$length >= $this->last) {
      for (
$i=1$i <= $this->last$i++) {
        
$scroll[] = $i;
      }
    } elseif ( 
$start <= ) {
      for (
$i=1$i <= $length$i++) {
        
$scroll[] = $i;
      }
    } elseif ( 
$end >= $this->last ) {
      for (
$i=($this->last $length 1); $i <= $this->last$i++) {
        
$scroll[] = $i;
      }
    } else {
      for (
$i=$start$i <= $end$i++) {
        
$scroll[] = $i;
      }
    } 
// end else
    
return $scroll;
  } 
// end function get_scroll 


$length lets you set the number of pages (maximum) in your scroll bar. $this->current and $this->last are properties that I hold in my paging class for the current page and the last page (derived from mysql_num_rows). You will need to add these to your class or pass them into the function another way.

If you aren't listing all the pages, You should also create links for First and Last so it's quicker to jump there.

Reply With Quote
  #19  
Old July 23rd, 2003, 02:42 AM
worchyld worchyld is offline
Registered User
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
How do I call that function, and where?

Reply With Quote
  #20  
Old July 23rd, 2003, 04:51 AM
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: 16
Send a message via ICQ to avit
I have my function simply return an array of numbers, so you still need to format them to your list of links. You can put this in your class between your Prev and Next links. Replace the for loop with:

PHP Code:
 $scroll $this->get_scroll(10);
  foreach (
$scroll as $i) {
    if (
$i <> $page) {
      
$nav .= " <a href='$PHP_SELF?page=$i'>$i</a> |";
    } else {
      
$nav .= " <b>$i</b> |";
    }
  }
  
$nav*=*ereg_replace("|$",*"",*$nav); 


I just saw a website tonight that does it a little differently. They had links for 1-10, 11-20, 21-30... depending on which page you are currently viewing. Probably a better standard, better than the way mine is done... I might change my function.

Reply With Quote
  #21  
Old July 23rd, 2003, 04:53 AM
worchyld worchyld is offline
Registered User
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
Thanks

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Getting Joe O'Donnell's Paging Class to Page


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap