RE: excel tables to mysql tables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Kerem,

I wrote the following code to do this some time ago. It could probably be
improved by using the header row in the spreadsheet  to generate the keys
for an associative array instead. This might make life easier when it comes
to generating your sql query. You'll just have to save the spreadsheet as a
csv file to make it work.

Regards

Chris

<code>

<?php

$datalist = fopen("filename.csv", "r");

while(!feof($datalist))
{
	$datalistentries = fgetcsv($datalist, 2500, ",");
	$datalistentriesprocessed[] = $datalistentries;
}

$z = count($datalistentriesprocessed);

for ($n=0; $n<$z; $n++)
{
	
	$entry = $datalistentriesprocessed[$n];
	
	addslashes(&$entry[1]);
	addslashes(&$entry[2]);
	
	$query="update tablename set fieldName1 = '".$entry[1]."' where
FieldName2 = '".$entry[0]."'";
	dbconnect("user", "pass");
	$result=mysql_query($query);
	$rowid=mysql_insert_id();
	echo $rowid;
}

fclose($datalist);

?>

</code>

-----Original Message-----
From: arslanli [mailto:arslanli@itu.edu.tr]
Sent: 11 September 2003 08:10
To: php-windows@lists.php.net
Subject: excel tables to mysql tables


I have 4500 records in excel tables waiting to be insert into mysql
structure ....did anyone done this before i need it so much......


Kerem Arslanli
Istanbul Technical University
UEPRC
 
If you are not the intended recipient of this e-mail, please preserve the
confidentiality of it and advise the sender immediately of any error in
transmission. Any disclosure, copying, distribution or action taken, or
omitted to be taken, by an unauthorised recipient in reliance upon the
contents of this e-mail is prohibited. Somerfield cannot accept liability
for any damage which you may sustain as a result of software viruses so
please carry out your own virus checks before opening an attachment. In
replying to this e-mail you are granting the right for that reply to be
forwarded to any other individual within the business and also to be read by
others. Any views expressed by an individual within this message do not
necessarily reflect the views of Somerfield.  Somerfield reserves the right
to intercept, monitor and record communications for lawful business
purposes.

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux