Sr. Web Developer
mediabistro.com
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume

Comments for: kenlin012405

Message # 1031001:
Date: 10/20/05 15:07
By: Vincent Meurink
Subject: Import excel data on mysql

Here is some snippet of a code that uploads tab delimited into mysql. Remember that the files needs to have the same structure as you db table.

<?
# first create a mysql connection here.

# after that, CHANGE BELOW.

$fcontents = file ('./test.xls');
# expects the csv file to be in the same dir as this script


for($i=0; $i<sizeof($fcontents); $i++) {
$fcontents[$i] = str_replace("'","&#39",$fcontents[$i]);
$line = trim($fcontents[$i], '\t');
$arr = explode("\t", $line);
#if your data is comma separated
# instead of tab separated,
# change the '\t' above to ','

$sql = "insert into TABLENAME values ('". implode("','", $arr) ."')";
mysql_query($sql);
echo $sql ."<br>\n";
if(mysql_error()) {
echo mysql_error() ."<br>\n";
}
}
?>

Cheerio

Previous Message | Next Message


Comments:
how can i import any file in a php filepkumarus10/15/07 22:30
import excel data on mysqldeee02/10/06 01:51
Import excel data on mysqlVincent Meurink10/20/05 15:07
RE: import excel data on mysqlAmal06/16/05 09:12
Read this!Quantum05/02/05 19:35
Populate combo box using <for stament>Matt05/01/05 14:06
RE: How to export data from access to my sqlsrisathiyan04/20/05 13:26
thanksbakwa dunks04/14/05 10:20
How to export data from access to my sqlLeo04/12/05 10:06
php/mysqlaamir04/06/05 12:43
import excel data on mysqlGERARD04/04/05 08:50
RE: php/mysql app devJeremy Walker03/15/05 20:42
RE: Need help to catch parameters in the url Jeremy Walker03/15/05 20:40
RE: Need help to catch parameters in the url vicky03/09/05 13:46
RE: Databasesriram Goteti03/06/05 12:19
DatabaseYari Tillett02/25/05 21:19
i need help to generate database in mysqlkarate devang02/25/05 00:27
php/mysql app devroger leonard02/22/05 08:11
generate codingaishah02/21/05 03:02
Re:php commandsPhilip Dimabuyu02/10/05 03:19
Prefer to use SQLyogKaram02/09/05 23:03
Need help to upload the file to serverDayananda.MR02/02/05 08:25
Report to Excel spreadsheets and MS Access Dayananda.MR01/24/05 17:03
 

If you are looking for help, please post on the appropriate forum here. Your questions will be answered much more quickly.

Add A Comment:

Name:

Email:

Subject:

Message:

To reduce spam posts, messages are now manually approved

You are not [logged in]. That means your account will not get credit for this post.