|
|
|
ถ้าจะไม่เอาแถวแรก เวลาที่ import excel csv ต้องทำอย่างไร |
|
|
|
|
|
|
|
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP & CSV To MySQL</title>
</head>
<body>
<?
move_uploaded_file($_FILES["fileCSV"]["tmp_name"],$_FILES["fileCSV"]["name"]); // Copy/Upload CSV
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database"); // Conect to MySQL
$objDB = mysql_select_db("mydatabase");
$objCSV = fopen($_FILES["fileCSV"]["name"], "r");
$i = 0;
while (($objArr = fgetcsv($objCSV, 1000, ",")) !== FALSE) {
$i++;
if($i > 1)
{
$strSQL = "INSERT INTO customer ";
$strSQL .="(CustomerID,Name,Email,CountryCode,Budget,Used) ";
$strSQL .="VALUES ";
$strSQL .="('".$objArr[0]."','".$objArr[1]."','".$objArr[2]."' ";
$strSQL .=",'".$objArr[3]."','".$objArr[4]."','".$objArr[5]."') ";
$objQuery = mysql_query($strSQL);
}
}
fclose($objCSV);
echo "Upload & Import Done.";
?>
</table>
</body>
</html>
Go to : PHP Upload and Convert/Import CSV To MySQL Database
|
|
|
|
|
Date :
2011-09-01 13:44:09 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณมาก มากค่ะ
|
|
|
|
|
Date :
2011-09-01 16:22:58 |
By :
aobmi |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|