|
 |
|
สอบถามการ code ที่สามารถตรวจสอบ form upload and Import CSV |
|
 |
|
|
 |
 |
|
สอบถาม code เช็ค form upload and Import CSV จากไฟล์ excel สามารถเช็คได้ว่ามีไฟล์ที่อัพโหลด เข้า database หรือไม่ คือถ้ายังไม่ได้เลือกไฟล์ แล้วกด import เลย มันจะเก็บฐานข้อมูลป่าว เป็น 1000ๆๆ เรคอร์ดเลยค่ะแก้ปัญหายังไงดีค่ะ แล้วถ้าโหลดแล้วจะเช็คได้ไงว่าเข้าทุกเรคอร์ด
code upload
Code (PHP)
<table width="490" height="235" border="0" align="center">
<tr>
<td height="34"> </td>
</tr>
<tr>
<td width="447"><div align="center" class="style3">
<p>อัพโหลดข้อมูลลงฐานข้อมูล</p>
<p> </p>
</div></td>
</tr>
<tr>
<td height="91"><form action="uploadimport.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<div align="center">
<p align="center">
<input name="fileCSV" type="file" class="style5" id="fileCSV" size="30" />
<input name="btnSubmit" type="button" class="style5" id="btnSubmit" value="upload" />
</p>
<p align="center"> </p>
</div>
</form></td>
</tr>
<tr>
<td><p><span class="style1">*หมายเหตุ การอัพโหลดไฟล์ excel ต้องทำการบันทึกไฟล์เป็น .crv เช่น vendor.crv </span></p>
<p class="style5"> </p></td>
</tr>
</table>
code import
Code (PHP)
<?
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("test");
mysql_query("SET NAMES TIS620");
$objCSV = fopen($_FILES["fileCSV"]["name"], "r");
$i = 0;
while (($objArr = fgetcsv($objCSV, 1000, ",")) !== FALSE) {
$i++;
if($i > 1)
{
$strSQL = "INSERT INTO vendor ";
$strSQL .="(id,location,payvoucher,vendorcode,vendorname,chequeno, pmtdate,transferamout,witholdingtax,accnumber,bankname,idcradnumber,password) ";
$strSQL .="VALUES ";
$strSQL .="('".$objArr[0]."','".$objArr[1]."','".$objArr[2]."' ";
$strSQL .=",'".$objArr[3]."','".$objArr[4]."','".$objArr[5]."' ";
$strSQL .=",'".$objArr[6]."','".$objArr[7]."','".$objArr[8]."' ";
$strSQL .=",'".$objArr[9]."','".$objArr[10]."','".$objArr[11]."','".$objArr[12]."')";
$objQuery = mysql_query($strSQL);
}
}
fclose($objCSV);
echo "<center><font color=\"red\">เพิ่มรายการชำระหนี้เรียบร้อย กำลังกลับสู่หน้าหลัก...</font></center>";
?>
Tag : PHP

|
|
 |
 |
 |
 |
Date :
2012-08-15 09:30:51 |
By :
ploy |
View :
1041 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณจะต้องสร้างตัวแปร Array ที่มี Index ตามจำนวน Rows ครับ จากนั้นก็เก็บสถานะการ Insert ว่าลงทุก Record หรือไม่ หรือไม่ก็ใช้ Transaction เข้ามาช่วยครับ
|
 |
 |
 |
 |
Date :
2012-08-15 13:54:38 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณค่ะ พอมีตัวอย่าง code ไมค่ะ
|
 |
 |
 |
 |
Date :
2012-08-15 14:22:56 |
By :
พลอย |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|