Jump to content

Recommended Posts

I have implemented this but i seem to be having problems. When i go to the next page it changes this statement:

 

select * from sellproperty WHERE buylet='Buy' limit -10, 10

 

to this when i click on e.g. page 2.

 

select * from sellproperty WHERE buylet='Buy' limit 0, 10

 

but it does not like this statement and throws an error because it should be 10, 10 not -10, 10 i assume .

 

Now this is not the only problem i am having. I would have thought that when i go through the pages it would go up like so 10, 10 - 20, 10 - 30, 10 etc but page 1, 2 and 3 all say -10, 10.

 

My first question is how do i remove the - and also why is my code not going up in 10's?

 

Here is the code:

 

 

 class Pager 
   { 
       function getPagerData($numHits, $limit, $page) 
       { 
           $numHits  = (int) $numHits; 
           $limit    = max((int) $limit, 1); 
           $page     = (int) $page; 
           $numPages = ceil($numHits / $limit); 

           $page = max($page, 1); 
           $page = min($page, $numPages); 

           $offset = ($page - 1) * $limit; 

           $ret = new stdClass; 

           $ret->offset   = $offset; 
           $ret->limit    = $limit; 
           $ret->numPages = $numPages; 
           $ret->page     = $page; 

           return $ret; 
       } 
   } 



// get the pager input values 
    $page = $_GET['page']; 
    $limit = 10; 
    $result = mysql_query("select count(*) FROM sellproperty WHERE $stored");
    $total = mysql_result($result, 0, 0);


    // work out the pager values 
    $pager  = Pager::getPagerData($total, $limit, $page); 
    $offset = $pager->offset; 
    $limit  = $pager->limit; 
    $page   = $pager->page; 



// output paging system (could also do it before we output the page content) 
    if ($page == 1) // this is the first page - there is no previous page 
        echo "Previous"; 
    else            // not the first page, link to the previous page 
        echo "<a href=\"property-search.php?set=$setquery&querypage=" . ($page - 1) . "\">Previous</a>"; 

    for ($i = 1; $i <= $pager->numPages; $i++) { 
        echo " | "; 
        if ($i == $pager->page) 
            echo "Page $i"; 
        else 
            echo "<a href=\"property-search.php?set=$setquery&page=$i\">Page $i</a>"; 
    } 

    if ($page == $pager->numPages) // this is the last page - there is no next page 
        echo " | Next"; 
    else            // not the last page, link to the next page 
        echo "<a href=\"property-search.php?set=$setquery&page=" . ($page + 1) . "\"> | Next</a>";

Link to comment
https://forums.phpfreaks.com/topic/64633-php-pagination/
Share on other sites

That is a different problem they solved.

 

It looks like the problem is here: 

 

$offset = ($page - 1) * $limit; 

 

Say i click on page 1 i get -10, 10 but i should be getting 10, 10

And if i click on page 2 i should get 20, 10 not -10, 10 like i am doing at the moment.

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/64633-php-pagination/#findComment-322539
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.