troubleshooting Question

Paginate CSV Output

Avatar of theresel
thereselFlag for Canada asked on
Microsoft AccessPHP
9 Comments1 Solution1668 ViewsLast Modified:

I need a solution to paginate my csv file output when viewing on the web.  The csv file will become quite large and I'd like to split it to 20 entries per page with links to the next or previous pages.

I already have the following script to show the results which is working fine, just need a little polishing for pagination and including the column titles on each page.  Of course it's enclosed in the php statement...

$dir_name = "C:/wamp/logs/ocwa.csv";
$fh = fopen($dir_name, "r");
$row = 1;

echo "<table width=\"100%\" border=\"1\">\n";
while(($data = fgetcsv($fh, 1000, ",")) !== FALSE)
    echo "<tr>\n";
    $num = count($data); // count the # of lines that exist
    $row++;  //increment the row variable to the next line
//output current line to the screen.
    for ($i=0; $i < $num; $i++)
          echo "<td>\n";
          echo $data[$i]."\n";
          echo "</td>\n";
    echo "</tr>\n";
echo "</table>\n";

//close file handler and delete file

Hope someone can help with a piece of code example.

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 9 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros