Make multiple Pages in PHP

Discussion in 'PHP' started by CuBz, Nov 13, 2007.

  1. #1
    How do you make multiple pages in PHP?

    EG/.

    If i made a page that shows all users that have registered, how would i make it show 30 on the page and then 30 on each other page but on the same script

    like PAGE.PHP?Page=2

    Cheers
     
    CuBz, Nov 13, 2007 IP
  2. commandos

    commandos Notable Member

    Messages:
    3,648
    Likes Received:
    329
    Best Answers:
    0
    Trophy Points:
    280
    #2
    - by using paging

    someone wrote a code recenlty here ... about paging ...

    or just search "paging php" in google
     
    commandos, Nov 13, 2007 IP
  3. bobb1589

    bobb1589 Peon

    Messages:
    289
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #3
    its called pagination ;-) ill write you a quick script real quick
     
    bobb1589, Nov 13, 2007 IP
    commandos likes this.
  4. greatlogix

    greatlogix Active Member

    Messages:
    664
    Likes Received:
    13
    Best Answers:
    1
    Trophy Points:
    85
    #4
    Just Google "paging in php" without quotes and you will find hundred's of tutorials on this topic
     
    greatlogix, Nov 13, 2007 IP
    commandos likes this.
  5. clinton

    clinton Well-Known Member

    Messages:
    2,166
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    110
    #5
    its farily simple but takes a while to make a function. Use the sql offset and limit commands will help. Just google it, also look around the forums, there are similar threads regarding this topic.
     
    clinton, Nov 13, 2007 IP
  6. bobb1589

    bobb1589 Peon

    Messages:
    289
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #6
    <?php
    
    $num_per_page = "10";
    
    $page = $_REQUEST['page'];
    
    if($page==NULL){
    	$page = 1;
    }
    
    $numrows = mysql_num_rows(mysql_query("SELECT * FROM tablename"));
    
    $start = $page * $num_per_page;
    
    $sql = mysql_query("SELECT * FROM tablename LIMIT $start,$num_per_page");
    
    while($r=mysql_fetch_assoc($sql)){
    	echo "put output php stuff here";
    }
    
    $pages = $numrows/$num_per_page;
    
    $prev = $page - 1;
    $next = $page + 1;
    
    echo "<a href=\"?page=1\">First</a>";
    echo "<a href=\"?page=".$prev."\">Prev</a>";
    
    for($i=0;$i<=$pages;$i++){
     if($i==$page){
    		echo "<a href=\"?page=".$i."\">[".$i."]</a>";
    	}else{
    		echo "<a href=\"?page=".$i."\">".$i."</a>";
    	}
    	
    }
    echo "<a href=\"?page=".$next."\">Next</a>";
    echo "<a href=\"?page=".$pages."\">Last</a>";
    
    ?>
    PHP:
    its a little glitchy but thats the idea behind it
     
    bobb1589, Nov 13, 2007 IP