Jump to content

pagination problems


jerryroy

Recommended Posts

the links in my code not working for some strange reason i don't know why heres a look at the code

  <?php
  
    $db = mysql_connect("localhost","root","docdre") or die ("Error Could not Connect".mysql_error());
            $dbn = "sitenews";
                mysql_select_db  ($dbn,$db) or die ("Select DB Error".mysql_error());
           
           $rows_per_page = 10;
            
            if(!isset($_GET['page']))
            {
		$page = 1;
		}
		else{
            $page = $_GET['page'];
            }
            $offset = (($page  * $rows_per_page) -  $rows_per_page);
            
                              
            $post = mysql_query("select * from post  limit $offset,$rows_per_page" );
          
              
            echo "Latest Blog!!!";
            
            while ($row = mysql_fetch_array($post) ){ 
         
            echo "<br>";
            echo "DATE ADDED: ";
            echo $row [ "date_added" ] ;
            echo "<br>";
            echo  "NAME: ";             
            echo $row ["user_name" ];
            echo "<br>";
            echo "SUBJECT: ";      
            echo $row ["subject" ];
            echo "<br>";
            echo "COMMENTS: ";     
            echo $row ["comments" ];
            echo "<br>";
            }
            
		$total_results = mysql_result(mysql_query("select count(*) as num from post"),0);
		$total_pages = ceil($total_results / $rows_per_page);
		echo "<center>Select a Page<br />";
		// Build Previous Link
if($page > 1){
    $prev = ($page - 1);
    echo "<a href=\"".$_SERVER['PHP_SELF']."?ref=viewpost?page=$prev\"><<Previous</a> ";//
}

for($i = 1; $i <= $total_pages; $i++){
    if(($page) == $i){
        echo "$i ";
        } else {
            echo "<a href=\"".$_SERVER['PHP_SELF']."?ref=viewpost?page=$i\">$i</a> ";//
    }
}

// Build Next Link
if($page < $total_pages){
    $next = ($page + 1);
    echo "<a href=\"".$_SERVER['PHP_SELF']."?ref=viewpost?page=$next\">Next>></a>";//
}
echo "</center>"; 
            
          
                mysql_close($db);
?>

Link to comment
https://forums.phpfreaks.com/topic/56141-pagination-problems/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.