【问题标题】:how to upload an excel sheet and compare it with data in database?如何上传excel表格并将其与数据库中的数据进行比较?
【发布时间】:2017-08-16 06:36:03
【问题描述】:

有人能弄清楚如何将 Excel 工作表上传到网络服务器并将其与现有数据进行比较。

假设我的数据库中有一些看起来类似于 Excel 工作表排列的数据。现在我需要上传一个 excel 表并将其与 DB 进行比较,并进行某种排序等等。最后,我需要将最终结果导入为 excel 并下载。所以同时我也需要删除上传的文件。

注意:我不需要代码.. 我需要有人向我解释这个概念,以便我可以自己尝试编码

【问题讨论】:

    标签: php excel spreadsheet


    【解决方案1】:

    检查一下:

    <form action="" enctype="multipart/form-data" method="post>
    <input type="file" name="txtFile" id="eskal"  /></br>
    <input type="submit" name="Import" value="Update Database" /> </b>
    </form>
    <?php
    if(isset($_POST["Import"]))
    {
    $host="localhost"; // Host name.
    $db_user="root";
    $db_password="";
    $db='test'; // Database name.
    $conn=mysql_connect($host,$db_user,$db_password) or die (mysql_error());
    mysql_select_db($db) or die (mysql_error());
    
    echo $filename=$_FILES["file"]["tmp_name"];
    //echo $ext=substr($filename,strrpos($filename,"."),(strlen($filename)-strrpos($filename,".")));
    
    
     if($_FILES["file"]["size"] > 0)
     {
    
      $file = fopen($filename, "r");
      while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE)
      {
       // You can compare your data inside this while loop as well as above the while loop.
       print_r($emapData);
       $sql = "INSERT into import(name,address,email,password) values('$emapData[0]','$emapData[1]')";
       mysql_query($sql);
     }
             fclose($file);
             echo "CSV File has been successfully Imported";
     }
     else
     echo "Invalid File:Please Upload CSV File";
    
    }
    ?>
    

    【讨论】:

    • 我不需要代码.. 我需要有人向我解释这个概念,以便我可以自己尝试编码
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-19
    • 1970-01-01
    • 2014-11-14
    • 2019-01-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多