homepage Welcome to WebmasterWorld Guest from 54.226.230.76
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
how to select a similar row in csv using php
saideep2007




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

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




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

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved