Monday, 25 November 2013

import CSV using php

//echo $_FILES["importBulkOrder"]["tmp_name"];
//die;
// path where your CSV file is located
define('CSV_PATH','D:/');

// Name of your CSV file
//$csv_file = CSV_PATH . "channelOrderingBulkUpload.csv";

$csv_file = $_FILES["importBulkOrder"]["tmp_name"];


$row = 1;
if (($handle = fopen($csv_file, "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        $num = count($data);
       // echo "<p> $num fields in line $row: <br /></p>\n";
        $row++;
        for ($c=0; $c < $num; $c++) {
            //echo $data[$c] . "<br />\n";
$col1 = $data[0];
             $col2 = $data[1];
             $col3 = $data[2];
$col4 = $data[3];
if($col1!=''&&$col2!=''&&$col3!=''&&$col4!=''){
$UpdateQuery ="update channel_detail_view set CMV_CHANNEL_DISPLAY_ORDER='".$col3."' where CMV_CHANNEL_CODE='".$col1."' and CMV_OPERATOR='".$col4."'";
mysql_query($UpdateQuery) or die(mysql_error());
}
        $data="";}
    }
    fclose($handle);
//die;
$mess="File data successfully imported.";
$url="channelDetails.php?mess=".base64_encode($mess);
redirectPage($url);
}

No comments:

Post a Comment