Page 1 of 1

ignoring multiple entries from a CSV file.

Posted: Thu Nov 26, 2009 2:01 pm
by Monotoko
Hiya :)

I have a search function on a webpage, and when someone searches for something, i want it too appear in a section of the admin panel....i have achieved this using a .csv file and the following script:

Code: Select all

                       <?php
 $row = 1; // a counter for line numbers
 $handle = fopen("test.csv", "r"); // open the test.csv file for reading
 while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { // while there are still lines to read
     $num = count($data); // the number of columns
    $row++; // next row
    for ($c=0; $c < $num; $c++) {
         echo $data[$c] . "<br />\n"; // print everything in the row
     }
 }
 fclose($handle); // close the file
?>
Now,what i need it to do, is if the timestamp column is the same (which would be stored as $data[3] in each case...) skip that entry and move to the next...what modifications should i make?

Re: ignoring multiple entries from a CSV file.

Posted: Thu Nov 26, 2009 3:59 pm
by Christopher
You need to add something like:

Code: Select all

if ($data[3] == $timestamp) {

Re: ignoring multiple entries from a CSV file.

Posted: Thu Nov 26, 2009 4:31 pm
by pickle
Pseudo code:

Code: Select all

$timestamp = some impossible value;
while(iterating through each line)
{
  if(current timestamp != $timestamp)
    echo the line
  
  $timestamp = current timestamp
}