php將資料匯出為execl檔案格式

來源:互聯網
上載者:User
php將資料匯出為execl檔案格式
  1. ?session_start();
  2. $sql_excel="";
  3. if(isset($_SESSION["excel"]))
  4. {
  5. $sql_excel=$_SESSION["excel"];
  6. }
  7. //unset($_SESSION["excel"]);
  8. $conn=mysql_connect("localhost","root","");
  9. mysql_select_db("test");
  10. mysql_query("set names utf8",$conn);
  11. $result=mysql_query($sql_excel);
  12. header("Content-type:application/vnd.ms-excel");
  13. header("Content-Disposition:attachment;filename=export_data.xls");
  14. //$result=mysql_query($sql_excel);
  15. $result=mysql_query($sql_excel);
  16. while($arr = mysql_fetch_assoc($result)){
  17. $content[]=$arr;
  18. }
  19. // print_r($content);
  20. $table = '
  21. $table .= '
  22. $table .= '
  23. foreach($content as $key=>$value){
  24. $table .= "
  25. $table .= "
  26. $table .= "
  27. $table .= "
  28. $table .= "
  29. $table .= "
  30. $table .= "
  31. $table .= '
  32. }
  33. $table .= '
  34. '; '; ';
  35. $table .= "
  36. "; '; '; '; '; '; '; '; ';
  37. $table .= '
  38. ';
    id 標題 電話 地址 審核狀態 內容 留言時間
    ".$value['id'].'".$value['title'].'".$value['phone'].'".$value['address'].'".$value['ischeck'].'".$value['content'].'".substr($value['datetime'],0,11).'
    ';
  39. echo $table;
  40. ?>
複製代碼
  1. session_start();
  2. $link= mysql_connect("localhost", "root", "") or die("Could not connect: " . mysql_error());
  3. mysql_query("set names utf8",$link);
  4. mysql_select_db("test");
  5. $sqls = "select * from news order by id desc ";
  6. $_SESSION["excel"]=$sqls;
  7. $rs1 = mysql_query($sqls);
  8. while($arr = mysql_fetch_assoc($rs1)){
  9. $content[]=$arr;
  10. }
  11. echo '
  12. echo '
  13. echo '
  14. echo '
  15. echo '
  16. echo '
  17. echo '
  18. echo '
  19. echo '
  20. echo '
  21. echo '
  22. echo '
  23. echo '
  24. echo '
  25. foreach ($content as $k => $v){
  26. echo "
  27. echo "
  28. echo "
  29. echo "
  30. echo "
  31. echo "
  32. echo "
  33. echo "
  34. }
  35. echo '
  36. '; '; '; '; '; '; '; '; '; '; '; '; '; ';
  37. echo "
  38. "; "; "; "; "; "; "; "; ";
  39. echo '';
  40. echo '
  41. ';
    視頻列表(index:在首頁顯示 lanmu:在視頻頁顯示)
    序號使用者uid顯示位置檔案名稱視頻名視頻介紹上傳時間
    $k{$v['title']}{$v['phone']}{$v['address']}{$v['ischeck']}{$v['content']}{$v['datetime']}
    ';
  42. //var_dump($content);
  43. mysql_free_result($rs1);
  44. mysql_close($link);
  45. ?>
複製代碼
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.