Current location: Hot Scripts Forums » Programming Languages » PHP » Paginating problem,extra empty page


Paginating problem,extra empty page

Reply
  #1 (permalink)  
Old 05-02-04, 04:50 AM
morrowind morrowind is offline
New Member
 
Join Date: May 2004
Location: Letala
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Question Paginating problem,extra empty page

Hello everyone! I have perhaps little but however "ugly" problem with paginating (MySQL + PHP). So, my paginating script works usually just fine, but there is a bug, that will occur in some situations.

I try to explain. If I set $limit to be 10 (for instance), and I have just those 10 records in my table, then the paginating script generates useless extra link and useless extra page. This additional page is empty but contains those useless links like this 1 2 Next 10. Besides that extra page is shown unnecessary warnings as "nothing to show". And if I have althoug 19 records in the table and I set $limit=19, the paginating script generates links in that way : 1 2 Next 19. If I click that link 2, an useless page will be opened with links and warning.

I have tried to get out of those extra link and page, but I could not to solve the problem. Could someone tell, what I should do, please?

PHP Code:

<?
//Connect to the database and some HTML
      
$limit 10// how many records is shown on the page    
   //how many rows
      
$query_count  ="SELECT id,item FROM items";
    
$result_count  mysql_query($query_count);  
      
//rows total
      
$totalrows      mysql_num_rows($result_count); 
      if(empty(
$page)){ 
          
$page 1
      } 
     
//how many pages is required to paginate
    
     
$limitvalue $page $limit - ($limit); 
//Selecting the data to show with LIMIT clause
$query   "SELECT id, item, description, image, status FROM items ";
$query  .= "ORDER BY id DESC LIMIT $limitvalue$limit ";

$result mysql_query($query); 
$nummysql_num_rows($result);
//Generating table with altering colors to show output of the query
//Paginating continues here, I assume that the problem is here(?)
if($page != 1){ 
        
$pageprev $page-1
         
        echo(
"<a href=\"$PHP_SELF?page=$pageprev\">Previous ".$limit."</a>&nbsp;&nbsp;&nbsp;"); 
    }
 else
 { 
       
  echo(
""); //If the first page, not showing "Previous" text
    

    
$numofpages $totalrows $limit
     
    for(
$i 1$i <= $numofpages$i++){ 
        if(
$i == $page)
  { 
            echo(
$i."&nbsp;"); 
        }
  else
  { 
            echo(
"<a href=\"$PHP_SELF?page=$i\">$i</a>&nbsp;"); 
        } 
    } 

        if(
$i == $page){ 
            echo(
$i."&nbsp;"); 
        }else{ 
            echo(
"<a href=\"$PHP_SELF?page=$i\">$i</a>&nbsp;"); 
        } 
   
    if((
$totalrows - ($limit $page)) >0){ //Maybe this row has the bug?
        
$pagenext $page//$pagenext = $page+1 was originally, it caused the bug, too
          
        
echo("&nbsp;&nbsp;&nbsp;<a href=\"$PHP_SELF?page=$pagenext\">Next ".$limit."</a>"); 
    }
 
 else{ 
//If the last page, not showing "next"
        
echo(""); 
    }    
 
 
echo 
"\n</body>\n</html>";
?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 05-02-04, 08:09 AM
the_mole001's Avatar
the_mole001 the_mole001 is offline
Newbie Coder
 
Join Date: Feb 2004
Location: Australia
Posts: 96
Thanks: 0
Thanked 0 Times in 0 Posts
Hello There,

I suggest you check out http://www.phpfreaks.com/tutorials/73/0.php for all your page numbering needs. I used that tutorial to help me with my page numbering and i've never had a drama or any miswanted links. I hope it helps you.

-Peter
__________________
Current Project: GGAC Website
Project Link: http://peter.5gigs.com/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 05-03-04, 04:32 AM
morrowind morrowind is offline
New Member
 
Join Date: May 2004
Location: Letala
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by the_mole001
Hello There,

I suggest you check out http://www.phpfreaks.com/tutorials/73/0.php for all your page numbering needs. I used that tutorial to help me with my page numbering and i've never had a drama or any miswanted links. I hope it helps you.

-Peter
Thank for your reply. Yes, this tutorial seems to be just for my problem
I think it can help me to create good-working paginating script.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Classified Ads skipper23 Perl 3 11-22-05 03:22 AM
Classified Ads skipper23 Perl 2 12-30-03 04:43 AM
Declared Functions skipper23 PHP 4 12-17-03 11:06 AM
index page not showing up skipper23 PHP 3 12-15-03 02:10 PM
Help me guys Mister B. ASP 1 09-09-03 10:12 PM


All times are GMT -5. The time now is 01:50 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.