Hi,
Ive been trying to sort this out by myself without to much success, I tried playing with the code posted by scrotaye above and havnt managed to get it to work ..
Also this code below:
Code: Select all
<?php
require 'db1.php';
$row = 1;
$handle = fopen("test.csv", "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
$row++;
// print_r ($data);
// echo $data[2]. "<br>";
$sql = mysql_query("SELECT code FROM items");
while ($row = mysql_fetch_array($sql)) {
$code = $row['code'];
if ($code == $data[2]) {
echo "update";
$sql1 = mysql_query("UPDATE items SET filter='$data[0]', item='$data[1]', code='$data[2]', description='$data[3]', price1='$data[4]', price2='$data[5]' WHERE code='$data[2]'");
if(!sql1) { echo 'update failed'; }
}else{
echo "insert";
$sql2 = mysql_query("INSERT INTO items (filter, item, code, description, price1, price2) VALUES ('$pro[0]', '$pro[1]', '$pro[2]', '$pro[3]', '$pro[4]', '$pro[5]'");
if(!sql2) { echo 'insert failed'; }
}
}
}
fclose($handle);
?>
The above code looks to create the correct arrays and also displays a line of code for each row, but doesnt write anything to the database, I would have thought atleast the least it would have echoed insert to the screen in the else statement. seems as tho the if and else staement arnt working at all ..
does using fgetcsv avoind having to use explode() or implode() functions?
A push in the right direction would be great ..
Thanks