Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

PHP to csv trouble

Options
  • 16-12-2008 10:57pm
    #1
    Registered Users Posts: 8,070 ✭✭✭


    [PHP]<?PHP

    $file_handle = fopen("urn.csv", "r");

    //while (!feof($file_handle) ) {
    for ($i = 0; $i <14; ++$i)
    {
    $line_of_text = fgetcsv($file_handle, 1024);

    $urnid = $line_of_text[0];
    $urn = $line_of_text[0];

    //dont mind this bit
    $urnlen = strlen($urn);
    $urndiff = 7-$urnlen;

    for ($ij = 0; $ij<$urndiff; $ij++){
    $urn.='0';
    }
    //dont mind this bit

    $barcodePersil = '1200280'.$urn.'4';
    $barcodeComfort = '5200281'.$urn.'4';


    $cr = "\n";
    $data .= $urnid . ',' . $barcodePersil . ',' . $barcodeComfort .$cr;


    $fp = fopen("a.csv","a"); // $fp is now the file pointer to file $filename
    if($fp){
    fwrite($fp,$data); // Write information to the file
    fclose($fp); // Close the file
    echo "File saved successfully";
    } else {
    echo "Error saving file!";
    }

    }

    fclose($file_handle);





    ?>
    [/PHP]

    It goes over the loop and writes same data over several rows
    any ideas? ive forced a for loop and still the same

    thanks


    EDIT: sorry i got it, it was the append data .=
    my bad


Advertisement