Forums

PHP

This topic is locked

Importting flat / excel / text file to php msql???

Posted 16 Oct 2003 17:51:00
1
has voted
16 Oct 2003 17:51:00 adam test posted:
Importting flat / excel / text file to php msql???

Anyone know how to upload a flat file / excel spreadsheet / tab comma deliminnated text file to a MSQL database using php or a dreamweaver mxp extension?

I need a simple solution that a client can upload their products and inventory to established tables in a MySQL database.

I'm not a programmer so an all-in-one solution would help! Thanks.

Replies

Replied 17 Oct 2003 19:29:14
17 Oct 2003 19:29:14 MAC MAC replied:
Replied 20 Oct 2003 00:13:57
20 Oct 2003 00:13:57 Michael Guntenaar replied:
For example you have an file called bla.csv
It has the value hello, hi, hoi

You could do this:

***********************************************************************************************************************
//Open the file and read the contents
$rows = file ( 'bla.csv' );

//For each line (newline) loop through the document
foreach ( $rows as $string ) {

//Seperate the values on the seperator in this case an ,
$value = explode(",", $string);

//You have just thrown your content into an array <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
$value[0] = hello
$value[1] = hi
$value[2] = hoi

//with you case you as
mysql_query("INSERT into Bla (field1, field2, field2) values ('".$value[0]."', '".$value[1]."', '".$value[2]."')";

//and so on and on <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
}
**************************************************************************************************************************

good luck <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

Reply to this topic