Jump to content

avia767

Members
  • Posts

    11
  • Joined

  • Last visited

avia767's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. thank you very much DavidAM, I got the right solution, I have set a combination in my DB wich are unique.
  2. hi every body, my pb is solved, I have this SQL statement $sql_insert = mysql_query ( "INSERT INTO test ( date, route, timeDEPARTURE, timeACTUALISED, delay ) VALUES ( '$datecsv_format', '$routeCSV', '$depCSV', '$actCSV', '$delayCSV' ) ON DUPLICATE KEY UPDATE date ='$datecsv_format', route = '$routeCSV', timeDEPARTURE = '$depCSV', timeACTUALISED = '$actCSV', delay = IF('$actCSV' == '00:00:00', '$delaycsv', timediff ( timeACTUALISED , timeDEPARTURE )) "); my probleme I'am sur is in the the IF condition here delay = IF('$actCSV' == '00:00:00', '$delaycsv', timediff( timeACTUALISED , timeDEPARTURE )) any help ?
  3. I got it, Thank you, here is the code I tried, it works if (($datecsv == $curr_date) OR ($datecsv == null)) { $sql_insert = mysql_query ("INSERT INTO test(date, leg, route) VALUES ('$curr_date', '$legcsv', '$routecsv') "); } elseif (!($datecsv == $curr_date)) { break; } Now I need to add my last condition wich is ; SQL update if data existe in my DB based on my daily CSV file uploaded, or SQL INSERT if data not exist. in my case I cannot use ON DUPLICATE KEY UPDATE, because any of my columns are UNIQUE !! no KEY no ODKU ! I did tried ON DUPLICATE KEY UPDATE id=id, it doesn't work for me. I tried the code below but it doesn't work : while (($fileop = fgetcsv ($handle, 1000, ",")) !==false) { $datecsv = $fileop[0]; $legcsv = $fileop[1]; $routecsv = $fileop[2]; $train_typecsv = $fileop[3]; if (($datecsv == $curr_date) OR ($datecsv == null)) { $result = mysql_query("SELECT * FROM test WHERE date='$curr_date'"); if (mysql_fetch_row($result) > 0) { $sql_update = mysql_query (" UPDATE test SET train_type = '$train_typecsv' WHERE route = $routecsv "); } else { $sql_insert = mysql_query ("INSERT INTO test(date, leg, route, train_route) VALUES ('$curr_date', '$legcsv', '$routecsv', '$train_typecsv') "); } } elseif (!($datecsv == $curr_date)) { break; }
  4. I might have a CSV file to upload like this with two or more date (wich is bad file, to avoid..) "Wed 18.06", " data1", "data2".,,,,, " ", "data", " data ",,,, " ", "data", " data ",,,, " ", "data", " data ",,,, " ", "data", " data ",,,, "Tue 19.06", " data1", "data2".,,,,, " ", "data", " data ",,,, I only need from users file like this "Wed 18.06", " data1", "data2".,,,,, " ", "data", " data ",,,, " ", "data", " data ",,,, " ", "data", " data ",,,, " ", "data", " data ",,,, I mean the first column has to contain only the current date and null (" ") To insure that, I need to set condition before any INSTERT and UPDATE into my DB is : here is the code .... $datecsv = $fileop[0]; $legcsv = $fileop[1]; $routecsv = $fileop[2]; if (($datecsv == $curr_date) AND ($datecsv == null)) { $sql_insert = mysql_query(" INSERT INTO test (date,leg,route) VALUES ('$curr_date', '$legcsv', '$routecsv')"); } else { echo 'Please select a dailly CSV file'; } it doesn't INSERT any row ???
  5. Hello your solution is great, actually I am haveing other considerations, I would like to slice my array as follow; from row 6 to skip the header to the last blue line for each day I upload. My CSV file "dateCSV", " data1", "data2".,,,,, " ", "data", " data ",,,, " ", "data", " data ",,,, " ", "data", " data ",,,, " ", "data", " data ",,,, <----- this is the last blue line "dateCSV +1 day", " data1", "data2".,,,,, " ", "data", " data ",,,, " ", "data", " data ",,,, " ", "data", " data ",,,, " ", "data", " data ",,,, " ", " ", " ",,,,, for each day, before uploading, I want for example IF dateCSV == Current Date, consider all the blue part any suggestion ?? Thank you in advance.
  6. it doesn't work, I got #1062 - Duplicate entry '2013-06-11-6233' for key 'date' because 'date' and 'route' can be duplicated, not as Unique !!
  7. my table columns - id [iNT (11), AUTO INCREMENT] PRIMARY KEY - date [DATE] - route [VARCHAR (9)] the entries for each columns could be duplicated, because every day I make instert and update. once data are correctly uploaded must be like this: id | date | route | ---------------------------- 1 | 2013.06.10 | A | 2 | 2013.06.10 | D | // data of day : 2013.06.10 3 | 2013.06.10 | G | 4 | 2013.06.11 | C | 5 | 2013.06.11 | C | 6 | 2013.06.11 | M | 7 | 2013.06.11 | Z | As you can see, date and route are duplicated for each day depending on data uploaded from my csv file.
  8. Hello guys, my ON DUPLICATE KEY UPDATE doesn't work correctely; data are uploaded every day AND many times for updates, from CSV files the CSV files look is csv file of yesterday: 1 " date" , " route ", 2 " 2013.06.10" , " A ", 3 " " , " D ", 4 " " , " G ", csv file of today: 1 " date" , " route ", 2 " 2013.06.11" , " C ", 3 " " , " D ", 4 " " , " M ", 5 " " , " Z ", My table in MySQL must be like this : id | date | route | ---------------------------- 1 | 2013.06.10 | A | 2 | 2013.06.10 | D | // data of day : 2013.06.10 3 | 2013.06.10 | G | 4 | 2013.06.11 | C | 5 | 2013.06.11 | D | 6 | 2013.06.11 | M | 7 | 2013.06.11 | Z | there are no unique columns, are are duplicated for each record, and route might have duplicate entries For each day there are insert and update, if ($date == $today OR $date==" ") { ​$sql = mysql_query ("INSERT INTO my_table (date, route) VALUES ('$date' , '$route') ON DUPLICATE KEY UPDATE date='$date', route ='$route' "); } I can insert and update any columns but here are the issue : 2) when I refrech my browser, data are loader again as much as I refrech my web-page, lines are duplicated 1 | 2013.06.10 | A | 2 | 2013.06.10 | D | 3 | 2013.06.10 | G | 4 | 2013.06.10 | A | // same data for 1st refresh 5 | 2013.06.10 | D | 6 | 2013.06.10 | G | 1 | 2013.06.10 | A | // same data for 2nd refresh 2 | 2013.06.10 | D | 3 | 2013.06.10 | G |
  9. Perfect, it works !!! now I want to read this CSV without the la last line and without knowing the line number of the file ?
  10. Hello, I have CSV data to import, I'm wondering how skip the 5th first lines of the header of my CSV file, I want to start reading my CSV file from line 6. Here is my CSV My PHP code <?php $conn = mysql_connect ("localhost","root","theboss") or die (mysql_error()); mysql_select_db ("big",$conn); $curr_date = date('d.m'); //echo $curr_date; if(isset($_POST['submit2'])) { $file = $_FILES ['file']['tmp_name']; $handle = fopen ($file, "r"); $fileop = fgetcsv ($handle, 1000, ","); while (($fileop = fgetcsv ($handle, 1000, ",")) !==false) { $date = $fileop[0]; $leg = $fileop[1]; $route = $fileop[2]; $cars_type = $fileop[3]; $car_reg = $fileop[5]; $pax = $fileop[8]; $std = $fileop[10]; if (stripos($date ,$curr_date) || $date =="") { $date = date('Y/m/d'); $sql = mysql_query ("INSERT INTO mvt_day (date, leg, route, cars_type, car_reg, pax, std) VALUES ('$date' , '$leg', '$route', '$car_type' , '$car_reg' , '$pax', '$std')"); } } fclose($handle); } ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.