note 62273 deleted from function.file by bjori
| From: | bjori@php.net | Date: | Wed, 22 Mar 2006 13:44:40 +0000 |
| Subject: | note 62273 deleted from function.file by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-106245@lists.php.net to get a copy of this message | ||
Note Submitter: dabigteez at yahoo dot com
----
Just a quickie note- I was trying to find a way to get the contents of a .CSV file into a database
and had to work at it quite a bit. the file was set up as a multi-dimensional array
eg:
item1 name,item1 description,item1 attribute,etc
item2 name,item2 description,item2 attribute,etc
item3 name,item3 description,item3 attribute,etc
I wanted to take the elements of each line and import them to the proper field of a certain table in
an MS SQL Server database.
the following code worked:
//get filecontents into array
$rsFileContents = file("C:/webserver/webpages/folder/".$BulkImportFile);
//loop through array elements and explode each element into a new array
$i=count($rsFileContents); //this gets the number of lines(elements) that need to be exploded
$x=0;
While($x<$i){
$newContents = explode(',', $rsFileContents[$x]);
//modify any elements that need to be modified and insert them into the proper db field
$weight=rtrim($newContents[10]);
$rsInputFileContents = $db->Execute("INSERT INTO tablename
(Item_Name,Item_Desc,Item_attribute) Values
('$newContents[0]','$newContents[1]','$newContents[2]',etc))");
$x++;
}
Hope this helps someone..........