Welcome to WebmasterWorld Guest from 54.145.44.134

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

how to select a similar row in csv using php

     

saideep2007

5:14 am on May 29, 2012 (gmt 0)

5+ Year Member



hai guys,


i have a query how to select a similar row in csv using fgetscv() in php...am trying to import data from csv to database using php..there i need to check for existing records in database ...if it exists in database it should skip the current row of csv and move forward..Kindly help me...here is my code




$xx= $_FILES['productImage']['name'];

$handle = fopen("csvs/$xx", "r");
while (($data = fgetcsv($handle, 19999, ",")) !== FALSE)
{
//echo $data['0']."<br>";

$sub1 = strip_tags($data['0']);
$sub2 = strip_tags($data['1']);
$sub3 = strip_tags($data['2']);
$sub4 = strip_tags($data['3']);
$sub5 = strip_tags($data['4']);
$sub6 = strip_tags($data['5']);
$sub7 = strip_tags($data['6']);
$sub8 = strip_tags($data['7']);
$sub9 = strip_tags($data['8']);

$diffy = str_replace("'","&#39;","$sub8");

$import = mysql_query("insert into dummy_tab(field1,field2,field3,field4,field5,field6,field7,field8,field9)
values('$sub1','$sub2','$sub3','$sub4','$sub5','$sub6','$sub7','$diffy','$sub9')") or die("".mysql_error());


coopster

11:27 pm on Jun 1, 2012 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



You could either run a SELECT query first to see if the key exists or you could use the MySQL-specific REPLACE statement.