Forum Moderators: coopster
$row = 1;
$handle = fopen ("HotelsLive.csv","r");
while (($data = fgetcsv ($handle,",")) !== FALSE)
{
$sql = 'INSERT into hotel(hotel_code,hotel, city_code, country_code, address, postcode,tel, fax,email,
starcode, boardbasis, category, rooms, hotel_area, public_desc, tube, bedroom_pic,front_pic,
map_pic, IsEnabled)
VALUES
("'.$data[0].'", "'.str_replace('"',"'",$data[1]).'", "'.$data[2].'","'.$data[3].'","'.$data[4].'"
,"'.$data[5].'","'.$data[6].'","'.$data[7].'","'.$data[8].'",'.$data[9].',"'.$data[10].'","'.$data[11].'"
,'.$data[12].',"'.str_replace('"',"'",$data[13]).'","'.str_replace('"',"'",$data[14]).'","'.str_replace('"',"'",$data[15]).'","'.$data[16].'","'.$data[17].'","'.$data[18].'","'.$data[19].'")';
echo $sql."<BR><BR>";
$add = mysql_query($sql) or die("Invalid query: " .
mysql_error().__LINE__.__FILE__);
$row++;
}
fclose($handle);
echo "All done!";
Now my question is, why is inserting duplicate rows? I know there are 8359 rows in this csv file but why does it carry on and insert 9400 odd everytime?
Thanks for your help!
I had a problem earlier with a csv upload -- excel deleted the values from the row, but didn't actually "delete" the row, so my upload code saw that there were a bunch of empty rows, and so inserted the empty data ...
-sned