Jump to content

Pagination


Northern Flame

Recommended Posts

i read through a tutorial here on phpfreaks

and i used the pagination script.

it worked fine for the most part,

but their were a few problems on it.

i fixed most of them but now i cant fix

this one.....

 

where it is suppose to show the pages,

PREV 1 2 3 4 5 6 7 8 NEXT

 

it only shows this

PREV 1

 

the "PREV" and "1" link

do point to the correct page and everything,

but why wont it show the other pages?

heres the part in the script that is suppose

to show the pages....

 

    for($i = 1; $i <= $numofpages; $i++){
        if($i == $page){
            echo($i." | ");
        }else{
            echo('<a href='.$PHP_SELF.'?page='.$i.'">'.$i.'</a> | ');
        }
    }

 

can anyone please help?

Link to comment
Share on other sites

<?php
include('includes/headerf.php');
echo '<div id=body align=center>';
$localhost = 'localhost';
$user = 'user';
$password = 'pass';
$database = 'database';

    @mysql_connect($localhost, $user, $password) or die("ERROR--CAN'T CONNECT TO SERVER");
    @mysql_select_db($database) or die("ERROR--CAN'T CONNECT TO DB");

    $limit          = 10;               
    $query_count    = "SELECT count(*) FROM ringtones";    
    $result_count   = mysql_query($query_count);    
    $totalrows      = mysql_num_rows($result_count); 
$PHP_SELF = $_SERVER['PHP_SELF'];

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

    $limitvalue = $page * $limit - ($limit); 
    $query  = "SELECT * FROM ringtones ORDER BY artist LIMIT $limitvalue, $limit";        
    $result = mysql_query($query) or die("Error: " . mysql_error()); 

    if($page != 1){ 
        $pageprev = $page - 1;
        
        echo('<a href="'.$PHP_SELF.'?&page='.$pageprev.'">«PREV</a> | '); 
    }else{
        echo("<font color=red>«PREV</font> | ");
    }

    $numofpages = $totalrows / $limit; 
    
    for($i = 1; $i <= $numofpages; $i++){
        if($i == $page){
            echo('<font color=red>'.$i."</font> | ");
        }else{
            echo('<a href='.$PHP_SELF.'?page='.$i.'">'.$i.'</a> | ');
            echo $numofpages;
        }
    }


    if(($totalrows % $limit) != 0){
        if($i == $page){
            echo('<font color=red>'.$i."</font> | ");
        }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»</a><br><br>"); 
    }else{
        echo("<br><br>"); 
    }

    if(mysql_num_rows($result) == 0){
        echo("Nothing to Display!");
    }

    $bgcolor = "#E0E0E0"; // light gray

    
    while($row = mysql_fetch_array($result)){
        if ($bgcolor == "#E0E0E0"){
            $bgcolor = "#FFFFFF";
        }else{
            $bgcolor = "#E0E0E0";
        }
    if($row['full'] == 'yes'){
echo '<a href="/qcp/full/'.$row["file"].'.qcp">'.$row["name"].' - '.$row["artist"].' - <font color=black>FULL!</font></a><br><br>';
} else{
    echo '<a href="/qcp/part/'.$row["file"].'.qcp">'.$row["name"].' - '.$row["artist"].'</a><br><br>';
    }
}
    
    mysql_free_result($result);
echo '</div>';
include('includes/template.php');
?>

Link to comment
Share on other sites

Well now I am awake, I can assure that your for loop works fine, as long you set $numofpages. This obviously means the problem is with either $totalrows or $limit. And as you manually do $limit it means the problem is with $totalrows!

 

So i recommend you check

 

$query_count = "SELECT count(*) FROM ringtones";
$result_count = mysql_query($query_count);
$totalrows = mysql_num_rows($result_count);

 

So add

 

or die(mysql_error());

 

on to them to check everything is working.

 

Also can you add

 

error_reporting(E_ALL);[/php

 

underneath the <?php, so its the first thing with in the php tags

 

~ Chocopi

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.