Home > Backend Development > PHP Tutorial > PHP import execel[xls] data table to mysql_PHP tutorial

PHP import execel[xls] data table to mysql_PHP tutorial

WBOY
Release: 2016-07-13 17:07:16
Original
1039 people have browsed it


<script><br> function import_check(){<br> var f_content = form1.file.value;<br> var fileext=f_content.substring(f_content.lastIndexOf("."),f_content.length)<br> Fileext=fileext.toLowerCase()<br> If (fileext!='.xls')<br> {<br> alert("Sorry, the imported data format must be an xls format file. Please adjust the format and upload it again, thank you!"); <br> Return false;<br> }<br> }<br> </script>








         



                                                                                                                                                                                       







                                                                                                                     
 Select the data table you want to import
                                                                                                     
         
 
 [Note]Data import format description:
1. Others. The imported data table file must be in the execel file format {.xls} Extension.
  2. The order of data imported into the execel file must be as follows: member name | membership card number | ID card | points | registration time | expiration date | contact phone number as shown below: < /td>


error_reporting(E_ALL ^ ​​E_NOTICE);

if($_POST){
$Import_TmpFile = $_FILES['file']['tmp_name'];
require_once '../../inc/connect.php';
require_once 'Excel/reader.php';
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('GB2312');
$data->read($Import_TmpFile);
$array =array();

for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) {
for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) {
$array[$i][$j] = $data->sheets[0]['cells'][$i][$j];
}
}
sava_data($array);

}
 function sava_data($array){ 
  $count =0; 
  $total =0;
  foreach( $array as $tmp){ 
     $Isql = "Select inte_card from gx_integral where inte_card='".$tmp[2]."'";
     $sql = "Insert into gx_integral(inte_name,inte_card,inte_status,inte_integral,inte_date,inte_date2,inte_tel) value(";
     $sql.="'".$tmp[1]."','".$tmp[2]."','".$tmp[3]."','".$tmp[4]."','".TtoD($tmp[5])."','".TtoD($tmp[6])."','".$tmp[7]."')";
    if(! mysql_num_rows(mysql_query($Isql) )){
     if( mysql_query($sql) ){
      $count++;
     }
    }
    $total++;
  }
  echo "<script>alert('共有".$total."条数据,导入".$count."条数据成功');</script>";
  
 }
 
 function TtoD($text){
  $jd1900 = GregorianToJD(1, 1, 1900)-2;
  $myJd = $text+$jd1900;
  $myDate = JDToGregorian($myJd);
  $myDate = explode('/',$myDate);
  $myDateStr = str_pad($myDate[2],4,'0', STR_PAD_LEFT)."-".str_pad($myDate[0],2,'0', STR_PAD_LEFT)."-".str_pad($myDate[1],2,'0', STR_PAD_LEFT);
  return $myDateStr;   
  }
?>

这里是用到Spreadsheet_Excel_Reader组件了,那read.php文件我就不附上了,自己下一个吧,好了最后申明本站原创转载请注明:  www.111cn.cn
 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/630430.htmlTechArticlestyle type=text/css !-- @import url(../style/admin.css); .STYLE1 { color: #FF0000; font-weight: bold; } .STYLE2 {color: #0033FF} -- /style script function import_check(){ var f_con...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template