Solved

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

Posted on 2012-03-31
4
643 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 83

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 83

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

809 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