Solved

Not getting data when trying to use fgetcsv() twice.

Posted on 2012-03-31
4
627 Views
Last Modified: 2012-03-31
I've opened up a csv file using:

$fp = @fopen ("myfile.csv","r");

if($fp){

$lastrow;

while (($data = fgetcsv($fp, 1000, ",")) !== FALSE) {      
      
      //get first day of data
     $lastrow = $data;
}

//cycle through again using lastrow as input
while (($data = fgetcsv($fp, 1000, ",")) !== FALSE) {      
      
  //use last row as input

}



I cycle through the csv file and get the last row using the above code.  I want to cycle through the csv file again using the last row as input to extract other data.

I've tried using fseek to reset the pointer to the beginning of the file but I get this error message:  Warning: fseek() [function.fseek]: stream does not support seeking in




How can I cycle through the csv file twice?
0
Comment
Question by:dmalovich
  • 2
  • 2
4 Comments
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 37791866
You can use rewind() http://us2.php.net/manual/en/function.rewind.php as long as it is a local file.  If it's 'http' or 'ftp', it doesn't work.
0
 

Author Comment

by:dmalovich
ID: 37791921
It is http.  Do you have any other suggestions maybe?
0
 
LVL 82

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 37791927
Close and re-open is your only choice I think.
0
 

Author Closing Comment

by:dmalovich
ID: 37791973
Yah I think so too, thanks......
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now