Can someone please write me a pagination?

Discussion in 'PHP' started by Kurt Whittingham, Mar 22, 2012.

  1. #1
    i have been on heaps of website trying to get scripts for a pagination but they all seem to not work.

    so i was wondering if someone could write me one..

    these are the things it will have:

    table name = supercross_race_reviews

    and thats it really.

    If anyone could help that would be awesome

    THANKS
    KURT
     
    Kurt Whittingham, Mar 22, 2012 IP
  2. Devitor

    Devitor Peon

    Messages:
    57
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    0
    #2
    A lot of it depends on how you currently display you content.

    if you are using a request to do a page number, and pulling it from a data base you should use LIMIT in you mysql. It just becomes a math problem at that point.
     
    Devitor, Mar 22, 2012 IP
  3. Kurt Whittingham

    Kurt Whittingham Member

    Messages:
    151
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    46
    #3
    Well this is the code thats in it now..

    <?php require('connect.php');
        
    
        $result = mysql_query("SELECT * FROM supercross_race_reviews ORDER BY id DESC") 
        or die(mysql_error());  
        
        echo "<table width='70%' cellspacing='10'>";
        // keeps getting the next row until there are no more to get
        while($row = mysql_fetch_array( $result )) {
        // Print out the contents of each row into a table
        echo "<tr><td>"; 
        // arrow
        echo ("<img src='arrow.gif'>"); echo "&nbsp;&nbsp;";
        // article name
        echo '<a style="font-size: 25px" href="'. $row['url'] .'">'. $row['article_name'] .'</a>';
        echo "</td></tr><tr><td>"; 
        // author + date
        echo $row['author']; echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"; echo $row['date'];
        echo "</td></tr><tr><td>";
        // Description
        echo "Brief Decription : "; echo "&nbsp;&nbsp;"; echo $row['description'];
        echo "<hr /></td></tr>";
    }
    
        ?>
    PHP:
    Thanks
     
    Kurt Whittingham, Mar 23, 2012 IP
  4. ssmm987

    ssmm987 Member

    Messages:
    180
    Likes Received:
    4
    Best Answers:
    3
    Trophy Points:
    43
    #4
    
    
    <?php
    $results_per_page=25;
    $page=is_numeric(@(int)$_GET['page'])?@(int)$_GET['page']:1;
    require('connect.php');
    
    //Get amount of pages//
    $arr=mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM supercross_race_reviews"));;
    $amount_of_results=$arr[0];
    $pages=ceil($arr/$results_per_page);
    
    //Fetch Results
    $result = mysql_query("SELECT * FROM supercross_race_reviews ORDER BY id DESC LIMIT ".($page-1)*$results_per_page.",".$results_per_page) 
    or die(mysql_error());  
    
    echo "<table width='70%' cellspacing='10'>";
    while($row = mysql_fetch_array( $result )) {
    	echo "<tr><td>"; 
    	echo ("<img src='arrow.gif'>"); echo "&nbsp;&nbsp;";
    	echo '<a style="font-size: 25px" href="'. $row['url'] .'">'. $row['article_name'] .'</a>';
    	echo "</td></tr><tr><td>"; 
    	echo $row['author']; echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"; echo $row['date'];
    	echo "</td></tr><tr><td>";
    	echo "Brief Decription : "; echo "&nbsp;&nbsp;"; echo $row['description'];
    	echo "<hr /></td></tr>";
    }
    
    PHP:
    Only thing left to do is displaying links to the different pages.

    (fyi, I can't check if it actually works. But I suppose you get the idea)
     
    ssmm987, Mar 23, 2012 IP
  5. Kurt Whittingham

    Kurt Whittingham Member

    Messages:
    151
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    46
    #5
    i tested it out and this error came

    Fatal error: Unsupported operand types in /home/motorbik/public_html/supercross race reviews.php on line 51
     
    Kurt Whittingham, Mar 25, 2012 IP