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
PHPHTML

Avatar of undefined
Last Comment
Lukasz Chmielewski

8/22/2022 - Mon
Bardobrave

Maybe this link provides some help to you

http://www.roscripts.com/PHP_pagination-70.html
Lukasz Chmielewski

Can you post at least a piece of that csv file ?
Lukasz Chmielewski

I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
daz1234

ASKER
Yes, that is the csv!
ASKER CERTIFIED SOLUTION
Lukasz Chmielewski

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Lukasz Chmielewski

if you need more items just change
$ipp = 2; // items per page
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!
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Lukasz Chmielewski

In the solution - it is omitted.
daz1234

ASKER
Roads, great coding - worked perfectly! Thanks for all your help with this.
Lukasz Chmielewski

No problem, cheers !
Your help has saved me hundreds of hours of internet surfing.
fblack61