Sandy505
Sandy505

Reputation: 888

PHP Ajax MySql Pagination

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++;
}

Upvotes: 1

Views: 799

Answers (1)

Rohit Chopra
Rohit Chopra

Reputation: 2821

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++;
    }
 ...

Upvotes: 1

Related Questions