Incrementing/decrementing a range of numbers

Discussion in 'Programming' started by spiney, Jan 7, 2008.

  1. #1
    Hello everyone,

    This has been bugging me for a bit now. I want to make a simple range of number that I can go next 10 or previous 10(without refreshing the page).

    example:

    A) prev 1 2 3 4 5 6 7 8 9 10 next

    if prev is clicked i should be like this

    B) prev -9 -8 -7 -6 -5 -4 -3 -2 -1 -0 next

    if next is clicked it goes back to A)

    if next is clicked again is should output

    C) prev 11 12 13 14 15 16 17 18 19 20 next

    and so on...

    I basically want to be able to scroll infinially both ways wiouth refreshing the page. This may seem easy for you guys but I can't figure it out. Help me please!!!
     
    spiney, Jan 7, 2008 IP
  2. LittleJonSupportSite

    LittleJonSupportSite Peon

    Messages:
    386
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Create a file called pagination.php


    
    
    <?
        $numofpages = $totalrows / $limit;
    
        for($i = 1; $i <= $numofpages; $i++){
            if($i == $page){
                echo($i." ");
            }else{
                echo("<a href=\"$PHP_SELF?page=$i">$i</a> ");
            }
        }
    
    
        if(($totalrows % $limit) != 0){
            if($i == $page){
                echo($i." ");
            }else{
                echo("<a href=\"$PHP_SELF?page=$i">$i</a> ");
            }
        }
    
    ?>
    
    
    
    Code (markup):

    Now on your main page you would do something like:


    
    <?        
            $limit = 10;
            if(empty($page)){
            $page = 1;
            }
            # Pagination Cofig
    
            $limitvalue = $page * $limit - ($limit);
            $sql = "select * from table";
            $result = mysql_query($sql);
            $totalrows = mysql_num_rows($result);
    
            while ($row = mysql_fetch_array($result)) {
            #show your results
             }
    
    #Now show pages
    include "pagination.php";
    ?>
    
    Code (markup):

    This example may be a little more complex then what you want because I am using mysql to do it.

    But based off this logic I am sure you can use it in a "for each" statement all the same

    where $i < 11 etc.


    Hope this helps!
     
    LittleJonSupportSite, Jan 7, 2008 IP
  3. spiney

    spiney Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the quick reply. I'm familiar with paging but this is kind of different. I will be in a range of -trillions to +trillions. I need the numbers to be created dynamically instead of gabbing sql db stored numbers. As a user clicks next/previous it will fetch the numbers in the sequence I specify. The main thing is that all this has to be done using AJAX so the user can "scroll" through the numbers without refreshing.
     
    spiney, Jan 7, 2008 IP