1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

only show 10 page links at a time on a pager

Discussion in 'PHP' started by mnymkr, Oct 17, 2007.

  1. #1
    I have successfully implemented a pager for my script thanks to reading tutorials...the problem is i have like 160 pagination links, (lost of records in the database)

    what i want to do is instead of showing links to all 160 pages, i want to show
    SEMrush
    ten page links at a time...then a link saying "next 10"

    i just can't figure out the logic or what to call it to search in google
     
    mnymkr, Oct 17, 2007 IP
    zerofunk likes this.
    SEMrush
  2. Lordy

    Lordy Peon

    Messages:
    1,644
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #2
    y=0
    if(x=0;x<10;x++)
    {
    //display the first ten results
    y++;
    }
    PHP:
    pass along the y variable by post, get, or request and then display the next results after y
     
    Lordy, Oct 17, 2007 IP
  3. Jeff Blake

    Jeff Blake Peon

    Messages:
    32
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    The records are in a database? If its SQL.. A query such as
    
    SELECT * FROM tablename LIMIT 10;
    
    Code (markup):
    Should work fine, and you can also use ORDER BY to organize them.

    To show the next 10 records it would be
    
    SELECT * FROM tablename LIMIT 10, 20;
    
    Code (markup):
     
    Jeff Blake, Oct 17, 2007 IP
  4. butters

    butters Peon

    Messages:
    497
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I'm not sure this is what you are looking for but maybe can help

    
    if (!$start) $start=0;
    $end = $start + 10;
    $next = $end+1;
    
    print("<a href="linklister.php?start=$next">Next >></a>");
    $eredm = mysql_query("SELECT * FROM table LIMIT $start,$end") or die(mysql_error());
    while($sor=@mysql_fetch_array($eredm)){
     // do whatever you want
    }
    
    Code (markup):
    hope it helps a bit
     
    butters, Oct 18, 2007 IP
    zerofunk likes this.
  5. ste.richards

    ste.richards Guest

    Messages:
    46
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    f(!isset($_GET['page'])) {
        $page_num = 1;
    } else {
       $page_num = $_GET['page'];
    }
    
    define("RECORDS_PER_PAGE", 100);
    
    $starting_offset = ($page-1) * RECORDS_PER_PAGE;
    
    $query = "SELECT * FROM my_table LIMIT ".$starting_offset.", ".RECORDS_PER_PAGE; 
    Code (markup):
    That should work OK.
     
    ste.richards, Oct 18, 2007 IP
  6. ste.richards

    ste.richards Guest

    Messages:
    46
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Oops.

    $starting_offset = ($page-1) * RECORDS_PER_PAGE;
    
    Code (markup):
    Should really be

    $starting_offset = ($page_num-1) * RECORDS_PER_PAGE;
    
    Code (markup):
     
    ste.richards, Oct 18, 2007 IP
  7. mnymkr

    mnymkr Well-Known Member

    Messages:
    2,329
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    120
    #7
    and this will give me the following?


    previous 1 2 3 4 5 6 7 8 9 10 next 10


    previous 10 11 12 13 14 15 16
     
    mnymkr, Oct 19, 2007 IP
  8. phantom

    phantom Well-Known Member

    Messages:
    1,508
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    140
    #8
    phantom, Oct 19, 2007 IP
  9. Koster

    Koster Guest

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    $page = 1;
    $limit_begin = 0;
    $limit_end = MAX_DOCUMENTS_PER_PAGE;
    
    //page id
    if( !empty($_GET['page']) ){
    	settype($_GET['page'],"integer");
    	$page = $_GET['page'];
    	$limit_begin = ($page-1)*$limit_end;
    }
    
    $query = "SELECT SQL_CALC_FOUND_ROWS field, other_field FROM some_table LIMIT ".$limit_begin.", ".$limit_end;
    $result = $db->query($query);
    
    while($row = $db->fetch_array($result)){
    	.....
    }
    
    if($db->num_rows($result)){
    	$t = $db->query_first("SELECT FOUND_ROWS()");
    	$pages = $t['FOUND_ROWS()']/$limit_end;
    
    	if( (int)$pages - $pages <0 )
    		$pages = (int)$pages+1;
    
    	if( $pages != 1 ){
    		for($i=1; $i<=$pages; $i++ ){
    			echo ( $i != $page ) ? " <a href=\"...&_GET['page']=".$i."\">".$i."</a> " : " ".$i." ";
    					if( $i != $pages )
    						echo " | ";
    		}
    	}
    }
    PHP:
     
    Koster, Oct 20, 2007 IP
  10. mnymkr

    mnymkr Well-Known Member

    Messages:
    2,329
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    120
    #10
    thanks i'll give some of these a try

    i always get nervous when i do pagination stuff on my scripts
     
    mnymkr, Oct 22, 2007 IP
  11. phpl33t

    phpl33t Banned

    Messages:
    456
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Hit me up if you need help, I will do for you for $5.
     
    phpl33t, Oct 22, 2007 IP
  12. mnymkr

    mnymkr Well-Known Member

    Messages:
    2,329
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    120
    #12
    5 bucks really...i am down for that!
     
    mnymkr, Oct 22, 2007 IP
  13. crazyryan

    crazyryan Well-Known Member

    Messages:
    3,087
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    175