Jump to content

Stuck on pagation


The_Anomaly

Recommended Posts

i have everything pretty much working but its displaying everything not just 5 at a time as i would like it to. I cant seem to find whats wrong. when i click the 1,2,3 links the page in the address bar says it has changed but all fields are still the same. Wanna take a look :)

[code]
<?php

    require_once('Connections/nwodb.php');
    @mysql_select_db("nwo") or die("ERROR--CAN'T CONNECT TO DB");
   


    $limit          = 5;              
    $query_Recordset1    = "SELECT * FROM person ORDER BY LastName ASC";   
    $result_count  = mysql_query($query_Recordset1);   
    $totalrows      = mysql_num_rows($result_count);
 

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

    $limitvalue = $page * $limit - ($limit); 
    //$query_Recordset1  = "SELECT * FROM person ORDER BY LastName ASC";       
    //$result = mysql_query($query) or die("Error: " . mysql_error()); 
     
      $Recordset1 = mysql_query($query_Recordset1, $nwodb) or die(mysql_error());
      $row_Recordset1 = mysql_fetch_assoc($Recordset1);
      $totalRows_Recordset1 = mysql_num_rows($Recordset1);
    if(mysql_num_rows($Recordset1) == 0)
{
        echo("Nothing to Display!");
        }

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

    echo("<table>");
    echo("<tr><td>");
    echo("Member_ID");
    echo("</td><td>");
    echo("Last Name");
    echo("</td><td>");
    echo("First Name");
    echo("</td></tr>");
   
    while($row_Recordset1 = mysql_fetch_array($Recordset1))
    {
        if ($bgcolor == "#E0E0E0")
  {
            $bgcolor = "#FFFFFF";
            }else
      {
                $bgcolor = "#E0E0E0";
              }
 
    echo("<tr bgcolor=".$bgcolor."><td width=\"20%\">");
    echo ($row_Recordset1["Person_ID"]);
    echo ("</td><td width=\"40%\">");     
    echo($row_Recordset1["LastName"]);
                  echo ("</td><td>");       
    echo($row_Recordset1["FirstName"]);
    echo("</td></tr>");
    }

    echo("</table>");
//shows the previous # entries link
    if($page != 1){ 
        $pageprev = $page--;         
        echo("<a href=\"pagation.php=$pageprev\">PREV".$limit."</a> "); 
    }else
          {
        echo("PREV ".$limit." ");
      }
//shows the number of pages that can be selected from
    $numofpages = $totalrows / $limit;     
    for($i = 1; $i <= $numofpages; $i++)
      {
        if($i == $page)
          {
            echo($i." ");
          }else
            {
                echo("<a href=\"pagation.php?page=$i\">$i</a> ");
            }
          }

//shows the next # enties link
    if(($totalrows % $limit) != 0)
      {
        if($i == $page){
            echo($i." ");
        }else
          {
            echo("<a href=\"pagation.php?page=$i\">$i</a> ");
          }
      }

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

?>
[/code]

I know its sloppy right now :|
Link to comment
Share on other sites

take a look at this and change whats needed ok

good luck


[code]

<?

//add database

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

$max_results = 1;

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

$query="select * from messages_copied  LIMIT $from, $max_results";


$result=mysql_query($query);
while($record=mysql_fetch_assoc($result)){


echo"<table align='center' width='300'border='4' bordercolor='black'><td align='left'><b>Members Id:<font color='red'><br>".$record["sent_id"]."</font><br> User Name: <font color='red'><br>".$record["members_name"]."</font><br>
Sent Time: <font color='red'><br>".$record["time"]."</font> <br> Sent Date <font color='red'><br>".$record["date"]."</font> </b></td><td align='center' valign='top'><b>Members Message <font color='red'>$page</font><b>
<br><br><b><div align='left'><textarea col='7' rows='7'style='color: white; background-color: #A0C0F0'>".$record["message"]."</textarea></td></b></div><table>";





echo "<table align='center' width='300'border='4' bordercolor='black'><td align='center'><b>";


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


$total_pages = ceil($total_results / $max_results);





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

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


if($page < $total_pages){
    $next = ($page + 1);
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\"></a>";

}

}

?>
[/code]
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.