|
|
|
มี 2 ตาราง ต้องการจะ import ข้อมูลจากไฟล์ xml โดยเลือกที่จะเอาข้อมูลลงตารางจาก list menu ยังไงครับ |
|
|
|
|
|
|
|
ตัวอย่าง โค้ด from upload
Code (PHP)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>up load </title>
<script type="text/javascript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>
</head>
<body>
<table width="398" height="208" border="0" cellpadding="0" cellspacing="0">
<tr>
<td background="image/backfrom.jpg"><table width="384" height="85" border="0" cellpadding="0" cellspacing="0">
<form enctype="multipart/form-data" action="import.php" method="post">
<tr>
<td width="23" height="43"></td>
<td width="23"></td>
<td width="197"><input type="hidden" name="MAX_FILE_SIZE" value="2000000" />
<input name="file" type="file" />
</td>
<td width="141"> <label>
<select name="select" id="select">
<option>-เลือกฐานข้อมูล-</option>
<option value="1">profilecomputer</option>
<option value="2">temprofile</option>
</select>
</label> </td>
</tr>
<tr>
<td></td>
<td></td>
<td align="center"><input type="submit" value="Upload" />
</td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</form>
</table></td>
</tr>
</table>
</body>
</html>
ตัวอย่างไฟล์ ที่ทำการ import ข้อมูล
Code (PHP)
<?php require_once('./Connections/db_conn.php'); ?>
<?php
if ( $_FILES['file']['error'] ) {
die("upload error ");
}
//======Connect DB======================//
/* $m_host = "localhost";
$m_user = "root";
$m_pass = "123456";
$m_name = "profilecomputer"; */
mysql_connect($hostname_db_conn,$username_db_conn,$password_db_conn);
mysql_select_db($database_db_conn);
mysql_query("SET NAMES UTF8");
//======End Connect DB======================//
//======Get data from Excel======================//
$dom = DOMDocument::load( $_FILES['file']['tmp_name'] );
$rows = $dom->getElementsByTagName( 'Row' );
$row = 0;
foreach ($rows as $temp) {
$col = 0;
if($row==0) {
$row++; continue;
}
$cells = $temp->getElementsByTagName('Cell');
foreach( $cells as $cell ) {
if($col==0) $data1 = $cell->nodeValue;
if($col==1) $data2 = $cell->nodeValue;
if($col==2) $data3 = $cell->nodeValue;
if($col==3) $data4 = $cell->nodeValue;
if($col==4) $data5 = $cell->nodeValue;
if($col==5) $data6 = $cell->nodeValue;
if($col==6) $data7 = $cell->nodeValue;
if($col==7) $data8 = $cell->nodeValue;
if($col==8) $data9 = $cell->nodeValue;
if($col==9) $data10 = $cell->nodeValue;
if($col==10) $data11 = $cell->nodeValue;
if($col==11) $data12 = $cell->nodeValue;
if($col==12) $data13 = $cell->nodeValue;
if($col==13) $data14 = $cell->nodeValue;
if($col==14) $data15 = $cell->nodeValue;
if($col==15) $data16 = $cell->nodeValue;
if($col==16) $data17 = $cell->nodeValue;
if($col==17) $data18 = $cell->nodeValue;
if($col==18) $data19 = $cell->nodeValue;
if($col==19) $data20 = $cell->nodeValue;
if($col==20) $data21 = $cell->nodeValue;
if($col==21) $data22 = $cell->nodeValue;
if($col==22) $data23 = $cell->nodeValue;
if($col==23) $data24 = $cell->nodeValue;
if($col==24) $data25 = $cell->nodeValue;
if($col==25) $data26 = $cell->nodeValue;
if($col==26) $data27 = $cell->nodeValue;
if($col==27) $data28 = $cell->nodeValue;
if($col==28) $data29 = $cell->nodeValue;
if($col==29) $data30 = $cell->nodeValue;
if($col==30) $data31 = $cell->nodeValue;
if($col==31) $data32 = $cell->nodeValue;
if($col==32) $data33 = $cell->nodeValue;
if($col==33) $data34 = $cell->nodeValue;
if($col==34) $data35 = $cell->nodeValue;
if($col==35) $data36 = $cell->nodeValue;
if($col==36) $data37 = $cell->nodeValue;
$col++;
}
//======End Get data from Excel======================//
//==================Insert To DB ====================================//
if($_POST[select]==1){
echo "< insert into table 01 values( ) >";
}
else if($_POST[select]==2){
echo "< insert into table 02 values ( ) >";
}else
{
echo "< no table insert >";
}
$sql = " INSERT INTO profilecomputer(";
$sql .= " locBud,";
$sql .= " locFlr,";
$sql .= " oROELocation,";
$sql .= " Location1,";
$sql .= " TYPE,";
$sql .= " comID,";
$sql .= " comSN,";
$sql .= " Brand,";
$sql .= " Model,";
$sql .= " mtID,";
$sql .= " M_SerialNo,";
$sql .= " ownPin,";
$sql .= " ownTn,";
$sql .= " ownMail,";
$sql .= " ownComp,";
$sql .= " ownEvp,";
$sql .= " ownVp,";
$sql .= " ownAvp,";
$sql .= " ownDp,";
$sql .= " ownSc,";
$sql .= " Telephone,";
$sql .= " AssetCode,";
$sql .= " IPAddress,";
$sql .= " KeyboardID,";
$sql .= " K_SerialNo,";
$sql .= " startdate,";
$sql .= " dendline,";
$sql .= " workage,";
$sql .= " CPU,";
$sql .= " HDD,";
$sql .= " RAM,";
$sql .= " LAN,";
$sql .= " WLAN,";
$sql .= " BT,";
$sql .= " Infared,";
$sql .= " genaral,";
$sql .= " remark ";
$sql .= " ) VALUES ( ";
$sql .= " '$data1', ";
$sql .= " '$data2', ";
$sql .= " '$data3', ";
$sql .= " '$data4', ";
$sql .= " '$data5', ";
$sql .= " '$data6', ";
$sql .= " '$data7', ";
$sql .= " '$data8', ";
$sql .= " '$data9', ";
$sql .= " '$data10', ";
$sql .= " '$data11', ";
$sql .= " '$data12', ";
$sql .= " '$data13', ";
$sql .= " '$data14', ";
$sql .= " '$data15', ";
$sql .= " '$data16', ";
$sql .= " '$data17', ";
$sql .= " '$data18', ";
$sql .= " '$data19', ";
$sql .= " '$data20', ";
$sql .= " '$data21', ";
$sql .= " '$data22', ";
$sql .= " '$data23', ";
$sql .= " '$data24', ";
$sql .= " '$data25', ";
$sql .= " '$data26', ";
$sql .= " '$data27', ";
$sql .= " '$data28', ";
$sql .= " '$data29', ";
$sql .= " '$data30', ";
$sql .= " '$data31', ";
$sql .= " '$data32', ";
$sql .= " '$data33', ";
$sql .= " '$data34', ";
$sql .= " '$data35', ";
$sql .= " '$data36', ";
$sql .= " '$data37' ";
$sql .= " ) ";
mysql_query($sql) or die(mysql_error(). "<br />" . $sql) ;
/*mysql_query($sql) or die(mysql_error()) */
//==================End Insert To DB ====================================//
$row++;
}
echo "<a href=fromupload.php>inserst OK";
mysql_close();
?>
ผมอยากทราบว่าผมจะทำยังครับ ต้องสร้างไฟล์ import 2 ไฟล์ หรือ ต้องสร้างเงือนไขตรงที่ ไฟล์ import ไฟล์เดียว
ไฟล์ข้อมูล xmlเป็นไฟล์ตัวเดียวกันข้อมูลที่จะ เอาลงฐานข้อมูลเพื่อเปรียบเทียบกันเฉย ๆ
Tag : PHP, MySQL, CakePHP
|
|
|
|
|
|
Date :
2011-04-01 09:58:00 |
By :
thelak |
View :
1012 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
หลังจาก Import แล้วให้ทำการ insert ลงใน table ที่ 2 โดยใช้คำสั่ง INSERT SELECT ครับ
|
|
|
|
|
Date :
2011-04-02 00:27:47 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|