CSV upload

2 posts by 2 authors in: Forums > CMS Builder
Last Post: September 20, 2010   (RSS)

Re: [Christopherb] CSV upload

By Jason - September 20, 2010

Hi Chris,

What you will need is a field (or fields) from the CSV file that you can use to uniquely define a record.

So, for example, if a combination of title and website could uniquely describe a record, we can use these to check if the record already exists:



while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
if ( $row == 1){
$row++;
} else {

$where = "title ='".mysql_escape($data[0])."' AND website='".mysql_escape($data[7])."'";
$recCount = mysql_select_count_from('ourcustom_list',$where);

if($recCount==0){
//INSERT RECORD INTO THE DATABASE//
}

}
}


In this example, it searches for the number of records in ourcustom_list that have the title and the website of the current CSV record. If it returns 0, it means the record is not yet in the database. You can then add code to add it in. Note: you many need to change names to match what is in your database.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/