logic-unit
logic-unit

Reputation: 4313

PHP - fgetcsv() reset pointer

How do I reset the file pointer with fgetcsv()?

I have the loop below, nested inside another while loop. However it starts reading the CSV from the break point rather than the beginning after first run.

while($line2 = fgetcsv($fp2, $length2, $fildDelineate2)) {
        if($line[0] == $line2[0]) {
            $desc = addslashes(strip_tags($line2[6]));
            $import2 = "insert into $table2 values('$id','1',\"$line[1]\",'$desc','','0')";
            mysql_query($import2) or die('import2 '.mysql_error());
            $count++;
            break;
        }
}

Upvotes: 5

Views: 6758

Answers (3)

Query Master
Query Master

Reputation: 7097

Continue is the best solution .... try this

 continue 2 ;

Upvotes: 1

FtDRbwLXw6
FtDRbwLXw6

Reputation: 28899

You can use rewind() or fseek() to do this:

rewind($fp2);
// ...is the same as:
fseek($fp2, 0);

Upvotes: 15

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798764

rewind()

Upvotes: 2

Related Questions