1

I am using AJAX Pagination for displaying my records in application from MySQL using PHP. I have done that successfully but just need one solution:

I need to display a Serial No while displaying records like:

----------------------------
S.No   Name       Country  
----------------------------
1      Sandeep    India  
2      Rahul      Japan  
3      Riya       China   
4      Sohan      India  
...
50     James      USA

If I have set to show 20 results per page while paginating the first page shows serial no. 1 to 20 , 2nd page shows serial no 1 to 20 and 3rd page shows serial no 1 to 10.

But I want to show serial no. 1 - 20 in first page , 21- 40 in second page , 41- 50 in 3rd page.

How can I do this in PHP?

Here is my code:

$ssql = $ssql_select.$ssql_where." order by reg_date desc LIMIT $Page_Start , $Per_Page";
$rs=mysql_query($ssql, $cn) or die("MySQL error: ".mysql_error());
$ctr = 1;
while ($row = mysql_fetch_object($rs)) {

    echo "<td align=center>".$ctr."</td>";
    echo "<td align=center>".$row->name."</td>";
    echo "<td align=center>".$row->country."</td>";
    $ctr++;
}

1 Answer 1

1

Try

 ...
    while ($row = mysql_fetch_object($rs)) {

        echo "<td align=center>" . $ctr + $Page_Start . "</td>";
        echo "<td align=center>".$row->name."</td>";
        echo "<td align=center>".$row->country."</td>";
        $ctr++;
    }
 ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.