| Server IP : 104.21.37.246 / Your IP : 104.23.243.33 [ Web Server : Apache System : Linux cpanel01wh.bkk1.cloud.z.com 2.6.32-954.3.5.lve1.4.59.el6.x86_64 #1 SMP Thu Dec 6 05:11:00 EST 2018 x86_64 User : cp648411 ( 1354) PHP Version : 7.2.34 Disable Function : NONE Domains : 0 Domains MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/cp648411/www/homhuan.com/homhuanup/ |
Upload File : |
<?php include('../include/class.php');?>
<?php
$date = date("Y-m-d H:i:s");
// php function to convert csv to json format
function csvToJson($fname) {
// open csv file
if (!($fp = fopen($fname, 'r'))) {
die("Can't open file...");
}
//read csv headers
$key = fgetcsv($fp,"1024",",");
// parse csv rows into array
$json = array();
while ($row = fgetcsv($fp,"1024",",")) {
$json[] = array_combine($key, $row);
}
// release file handle
fclose($fp);
// encode array to json
return json_encode($json);
}
?>
<?php
$data = json_decode(csvToJson('sku_1_n.csv'), true);
$name_table = "product";
$name_table2 = "product_size";
$num2=0;
$num=0;
foreach ($data as $key => $value) {
$secrch = "code = '".$value['code']."'";
$list = array('table'=>$name_table,'where'=>$secrch);
$view = $view_db->view($list);
$result = $view_db->q_re($view);
while($row = $view_db->q_ro($result))
{
$secrch2 = "product_id='".$row['id']."'";
$list2 = array('table'=>$name_table2,'where'=>$secrch2);
$view2 = $view_db->view($list2);
$result2 = $view_db->q_re($view2);
//print_r($row);
while($row2 = $view_db->q_ro($result2))
{
if($row2['size']==$value['size']){
$data_new[$num2]['id'] = $row2['id'];
$data_new[$num2]['product_id'] = $row2['product_id'];
$data_new[$num2]['code'] = $value['code'];
$data_new[$num2]['sku'] = $value['sku'];
$data_new[$num2]['size'] = $value['size'];
$data_new[$num2]['price'] = $value['price'];
$num2++;
}
}
}
}
//UPDATE `product` SET `status`=0 WHERE `id`>0
foreach ($data_new as $key => $value) {
$list = array(
'table'=>$name_table,
'id'=>$value['product_id'],
'status'=>1,
'up_date'=>$date
);
$add = $actiondata_db->edit_db($list);
if($add['suc']==1){
echo "suc";
echo "<br>";
}
}
?>