Jump to content

Pagination Links not Working


webguync

Recommended Posts

From the tutorial on pagination from this site I have the following code, but don't get links only text. What do I have wrong?

 

<?php
if($page != 1){  
        $pageprev = $page--; 
         
        echo("<a href=\"$PHP_SELF&page=$pageprev\">PREV".$limit."</a> ");  
    }else{ 
        echo("PREV".$limit." "); 
    } 

    $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> "); 
        } 
    } 

    if(($totalrows - ($limit * $page)) > 0){ 
        $pagenext = $page++; 
          
        echo("<a href=\"$PHP_SELF?page=$pagenext\">NEXT".$limit."</a>");  
    }else{ 
        echo("NEXT".$limit);  
    } 
     
    mysql_free_result($result); 
    ?>

 

this produced PREV25 1 NEXT25 without links

Link to comment
Share on other sites

Yhere you go a little test for your database ok.

<?php

//database connection.

if(!isset($_GET['page'])){ 
    $page = 1; 
} else { 
    $page = $_GET['page']; 
} 

$max_results = 1; 

$from = (($page * $max_results) - $max_results); 

//database query.

$query="select * from what_ever  DESC LIMIT $from, $max_results ";

$result=mysql_query($query);

while($rec=mysql_fetch_assoc($result)){

$point_query="select * from blogs where what_ever='what_evrer' ";

$point_result=mysql_query($point_query)or die(mysql_error());

while($p=mysql_fetch_assoc($point_result)){

// show the information	

}

$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM what_ever"),0); 

if($page > 1){ 
    
$prev = ($page - 1); 
  
echo "<div align='center'><a href=\"".$_SERVER['PHP_SELF']."?page=$prev\">Prev</a>"; 

} 

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

if($page < $total_pages){ 
    $next = ($page + 1); 

// show other infomation.

} 
}
?>

Link to comment
Share on other sites

the limiting of records is working, but I am still not getting the Next and Previous records to work. The end result I would like is to display 25 records on a page, and then have a link, to the next 25, and backo the previous page (if there is one).

 

Here is my current code

<?php
//start a session
session_start();

//check for validity of user
$db_name="people";
$table_name ="Listing";
$connection = @mysql_connect("localhost", "username", "password")
or die (mysql_error());
$db = @mysql_select_db($db_name, $connection) or die (mysql_error());
$limit      = 25;                
    // Sets how many results shown per page 
     
$query_count    = "SELECT count(*) FROM $table_name";     
    // Sets what we want to pull from the database 
    
     
$result_count   = mysql_query($query_count);     
    // Pulls what we want from the database 
     
$totalrows  = mysql_num_rows($result_count);     
    // This counts the number of users 
if(empty($page)){    // Checks if the $page variable is empty (not set) 
$page = 1;      // If it is empty, we're on page 1 
} 

    $limitvalue = $page * $limit - ($limit);  
    // Ex: (2 * 25) - 25 = 25 <- data starts at 25 
//build and issue query
$sql ="SELECT id, f_name, l_name, company FROM $table_name ORDER BY company LIMIT $limitvalue, $limit";
$result = @mysql_query($sql, $connection) or die(mysql_error());
                   $limit          = 25;                
    $query_count    = "SELECT count(*) FROM $table_name";     
    $result_count   = mysql_query($query_count);     
    $totalrows      = mysql_num_rows($result_count);  

    if(empty($page)){ 
        $page = 1; 
    } 
         

    $limitvalue = $page * $limit - ($limit);  


    if(mysql_num_rows($result) == 0){ 
        echo("Nothing to Display!"); 
    } 
//create list block of results
$contact_list="<ul class='vertical_list'>";
while ($row = mysql_fetch_array($result)) {
         $id = $row['0'];
         $f_name=$row['1'];
         $l_name=$row['2'];
        $company=$row['3'];
         $contact_list .="<li>
        <a href=\"show_contact.php?id=$id\">$company,$l_name, $f_name, </a>";
}
$contact_list .="</li></ul>";
?>
<html>
<head>
<title>MySQL Results Display</title>
</head>
<body>

<p>Select a contact from the list below, to view a contact's record</p>
<? echo "$contact_list"; ?>
<?php
if(!isset($_GET['page'])){ 
    $page = 1; 
} else { 
    $page = $_GET['page']; 
}

    $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> "); 
        } 
    } 

    if(($totalrows - ($limit * $page)) > 0){ 
        $pagenext = $page++; 
          
        echo("<a href=\"$PHP_SELF?page=$pagenext\">NEXT".$limit."</a>");  
    }else{ 
        echo("NEXT".$limit);  
    } 
     
    mysql_free_result($result); 
    ?>
<p><a href="Recruiters.php"> Return to main menu</a></p>

</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.