PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, March 13, 2022

[FIXED] fgetcsv open at specific row?

 March 13, 2022     php     No comments   

Issue

Is there a way to use fgetcsv to open on a particular row?

I have a really big csv and would like to run around 100 lines at a time via ajax. I can easily stop the while loop, but how would I open on a particular line? Or is this impossible?


Solution

There's no simple way to start reading at row 100, but what you can do is read/set the position in the file like this:

$k = <previous position>;
fseek($file, $k);
while(...) {
   fgetcsv(...);
   ...
}
$k = ftell($file);   //new position

Now it's just a matter of preserving this position between page calls.



Answered By - Aleks G
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing