Link to home
Start Free TrialLog in
Avatar of daz1234
daz1234

asked on

How to add pagination to html table generated from .csv file

Hi experts,

I have an alphabetized table containing a lot of data to which I would like to add page numbers to (pagination). Here is the code as it stands:

<?php

     echo"<table border=\"0\"><tr>";
     foreach (range('A', 'Z') as $letter) {
        echo"<td><a href=\"rates.php?value=$letter\">$letter</a></td>";
     }    
     echo"</tr></table>";

      echo "<html><body><table>\n\n"; $f = fopen("rate.csv", "r");
      do{        

      if(strtoupper(substr($line[0],0,1)) == $_GET[value]){
          echo "<tr width=500>";        
          echo "<td width=200>" . $line[0]. "</td>";
          echo "<td width=100>" . $line[1]. "</td>";
          echo "<td width=100>" . $line[2]. "</td>";
          echo "<td width=100>" . $line[3]. "</td>";
          echo "<tr>";

        }
      }

      while (($line = fgetcsv($f)) !== false);
     
      fclose($f);

echo "\n</table></body></html>";

?>

Thanks
Avatar of Bardobrave
Bardobrave
Flag of Spain image

Maybe this link provides some help to you

http://www.roscripts.com/PHP_pagination-70.html
Can you post at least a piece of that csv file ?
Avatar of daz1234
daz1234

ASKER

Yes, that is the csv!
ASKER CERTIFIED SOLUTION
Avatar of Lukasz Chmielewski
Lukasz Chmielewski
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
if you need more items just change
$ipp = 2; // items per page
Avatar of daz1234

ASKER

Thanks Roads, I will check it out in the morning and let you know. One other thing, the very first line in the .csv file is actually the headings for the columns in the table - any way that first line could be omitted altogether? It shows under D as the first heading is Destination. I can just add a <tr> with the headings instead. Thanks!
In the solution - it is omitted.
Avatar of daz1234

ASKER

Roads, great coding - worked perfectly! Thanks for all your help with this.
No problem, cheers !