Jump to content

[SOLVED] Pagination Help


RealDrift

Recommended Posts

<?
include "includes/functions.php";
include "includes/db_connect.php";

session_start();
logincheck();
$username=$_SESSION['username'];

echo "<link rel=stylesheet href=includes/in.css type=text/css>";

?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.style19 {
font-size: 11px;
font-weight: bold;
}
.style20 {
font-size: 10px;
font-weight: bold;
color: #FFFFFF;
font-family: Verdana, Arial, Helvetica, sans-serif;
}
-->
</style>
</head>

<body>
  <table width="80%" border="0" align="center" cellspacing="5">
    <tr>
      <td colspan="4"><div align="center" class="style19">History </div><br>        <table width="100%" border="1" align="center" cellpadding="2" cellspacing="0" bordercolor="#000000" bordercolorlight="#000000" bordercolordark="#000000" rules= class=thinline>
          
          
          
          
          
        </table></td>
    </tr>
    
    <tr>
      <td width="294" height=""> <?php

$username=$_SESSION['username'];
    $limit          = 10;               
    $query_count    = "SELECT count(*) FROM goldies WHERE Sender='$username'";    
    $result_count   = mysql_query($query_count) or die("Error: " . mysql_error());    
    $totalrows      = mysql_result ($result_count, 0, 0);
    $numofpages     = ceil($totalrows/$limit); 

//    $page = (empty($_GET['page']) || !is_int($_GET['page']))?1:abs($_GET['page']);
//
//    $limitvalue = ($page-1) * $limit;
    $page = (empty($_GET['page']) || !is_int($_GET['page']))?1:$_GET['page'];
$end = $page *$limit;
$start = $end-$limit;
    $query  = "SELECT * FROM goldies WHERE Sender='$username' LIMIT $start, $end ";   
    $result = mysql_query($query) or die("Error: " . mysql_error()); 

    //Exit if no records to display
    if(mysql_num_rows($result) == 0){
        exit("Nothing to Display!");
    }

    //Create the table of output data
    echo "<table>\n";
    while($row = mysql_fetch_array($result)){
        //Alternate the row background color
        $bgcolor = ($bgcolor == "#737373")?'#737373':'#737373';
        //Display the row of data
        echo "<tr bgcolor=\"$bgcolor\">\n";
        echo "  <td>".$row["Receiver"]."</td>\n";
        echo "  <td>".$row["Amount"]."</td>\n";
        echo "  <td>".$row["Date"]."</td>\n";
        echo "</tr>";
    }
    echo "</table>\n";

    //Enable the Prev link if not first page
    if($page > 1){ 
        echo("<a href=\"creditshistory.php?page=".($page-1)."\">PREV</a> "); 
    }else{
        echo("PREV ");
    }

    //Create links for each page in report
    for($i=1; $i<=$numofpages; $i++){
        if($i == $page){
            echo "$i ";
        }else{
            echo "<a href=\"creditshistory.php?page=$i\">$i</a> ";
        }
    }

    //Enable the Next link if not last page
    if($page < $numofpages){
        echo("<a href=\"creditshistory.php?page=".($page+1)."\">NEXT</a>"); 
    }else{
        echo("NEXT"); 
    }
    
    mysql_free_result($result);

?> </td>
      <td width="17"> </td>
      <td width="273"> </td>
    </tr>
  </table>

</body>
</html>

 

try and tell me what happen

Link to comment
Share on other sites

  • Replies 126
  • Created
  • Last Reply

Top Posters In This Topic

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in C:\xampp\htdocs\game\creditshistory.php on line 101

 

sorry, i miss a dot

 

try

 

echo "page number : ". $page . "<br>";

 

Sensei following results for ur modification:

 

table shows and below it is this : PREV 1 2 3 page number : 1 number of pages : 3NEXT   

 

The problem still is that links have correct URLS but when i click them they only reload page to page '1'

Link to comment
Share on other sites

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in C:\xampp\htdocs\game\creditshistory.php on line 101

 

sorry, i miss a dot

 

try

 

echo "page number : ". $page . "<br>";

 

Sensei following results for ur modification:

 

table shows and below it is this : PREV 1 2 3 page number : 1 number of pages : 3NEXT     

 

The problem still is that links have correct URLS but when i click them they only reload page to page '1'

 

Alright do one more thing for me, change page=1 to page=2 in your URL, and see if it prints out page number: 2.

 

Then change $page to $_GET['page'] in your IF statement.

 

Link to comment
Share on other sites

interestingly enough when i put the page one URL in the address bar and load page 1, when i click page 2 link the page reloads to show page 1 but the url changes to page 2 url.

 

when i click page 3 the url changes to page 3 url, but the table shows page 1 data all the time

Link to comment
Share on other sites

The url changes when i go to different pages,

 

the table data always shows page 1 data and the 'page number' variable always echos '1' despite the url change

 

all i wanted was to give users of my site a better experience, easier navigation, a simple paging system, but NOOOOOOOOOOOOOO something had to go wrong! lol

Link to comment
Share on other sites

The url changes when i go to different pages,

 

the table data always shows page 1 data and the 'page number' variable always echos '1' despite the url change

 

all i wanted was to give users of my site a better experience, easier navigation, a simple paging system, but NOOOOOOOOOOOOOO something had to go wrong! lol

 

Can you please link us to your site, there is something seriously wrong with this.

 

And a screenshot of your database table DATA.

 

The script is fine. Also, do what Teng said, and tell us the results.

Link to comment
Share on other sites

the echo statement which says what page number it is? that one always says '1' despite url change

 

i cant link you to my site as it is hosted using xampp on my pc

 

i can get u a screenie of my db, hold on

 

So your saying that "?page=2" comes out "1" even when you put echo $_GET['page']; ?

 

Thankyou, screenshot would help.

Link to comment
Share on other sites

The url changes to ?page=2 when i click page 2 link and same with when i click page three or one.

 

But the data in the table stays dat from page 1 and the "page number :" variable says "1" all the time

 

uploading screenie for db, i will upload screenie of site after this:

 

pagekz2.jpg Database image

Link to comment
Share on other sites

Alright, um... do me a favor.

 

I want you to print out $page after each time it is being change.

 

I.E.

$page = (empty($_GET['page']) || !is_int($_GET['page']))?1:abs($_GET['page']);

   $limitvalue = ($page-1) * $limit;
$limitrange = $limitvalue+$limit;

 

between the $page and $limitvalue, add a echo $page, to see where the data is being changed during the process. try this for each line the $page is being used in, or changed.

 

But a $page . "< br >";

 

and tell me what you get.

Link to comment
Share on other sites

i understand what u want me to do

 

but i dnt think me and u r looking at the same script. The script i have now after changing it on urs and teng's command:

 

<?php

$username=$_SESSION['username'];
    $limit          = 10;               
    $query_count    = "SELECT count(*) FROM goldies WHERE Sender='$username'";    
    $result_count   = mysql_query($query_count) or die("Error: " . mysql_error());    
    $totalrows      = mysql_result ($result_count, 0, 0);
    $numofpages     = ceil($totalrows/$limit); 

//    $page = (empty($_GET['page']) || !is_int($_GET['page']))?1:abs($_GET['page']);
//
//    $limitvalue = ($page-1) * $limit;
    $page = (empty($_GET['page']) || !is_int($_GET['page']))?1:$_GET['page'];
$end = $page *$limit;
$start = $end-$limit;
    $query  = "SELECT * FROM goldies WHERE Sender='$username' LIMIT $start, $end ";   
    $result = mysql_query($query) or die("Error: " . mysql_error()); 

    //Exit if no records to display
    if(mysql_num_rows($result) == 0){
        exit("Nothing to Display!");
    }

    //Create the table of output data
    echo "<table>\n";
    while($row = mysql_fetch_array($result)){
        //Alternate the row background color
        $bgcolor = ($bgcolor == "#737373")?'#737373':'#737373';
        //Display the row of data
        echo "<tr bgcolor=\"$bgcolor\">\n";
        echo "  <td>".$row["Receiver"]."</td>\n";
        echo "  <td>".$row["Amount"]."</td>\n";
        echo "  <td>".$row["Date"]."</td>\n";
        echo "</tr>";
    }
    echo "</table>\n";

    //Enable the Prev link if not first page
    if($_GET['page'] > 1){ 
        echo("<a href=\"creditshistory.php?page=".($page-1)."\">PREV</a> "); 
    }else{
        echo("PREV ");
    }

    //Create links for each page in report
    for($i=1; $i<=$numofpages; $i++){
        if($i == $_GET['page']){
            echo "$i ";
        }else{
            echo "<a href=\"creditshistory.php?page=$i\">$i</a> ";
        }
    }

   //Enable the Next link if not last page

echo "page number : ". $page . "
";
echo "number of pages : ". $numofpages;


   if($_GET['page'] != $numofpages){
        echo("<a href=\"creditshistory.php?page=".($page+1)."\">NEXT</a>"); 
    }else{
        echo("NEXT"); 
    }
    
    mysql_free_result($result);

?>

 

its got some bits commented out, i am confused as hell

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.