当前位置:Gxlcms > PHP教程 > php将数据导出为execl文件格式

php将数据导出为execl文件格式

时间:2021-07-01 10:21:17 帮助过:4人阅读

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. ';
  23. $table .= '
  24. ';
  25. foreach($content as $key=>$value){
  26. $table .= "
  27. ";
  28. $table .= "
  29. ';
  30. $table .= "
  31. ';
  32. $table .= "
  33. ';
  34. $table .= "
  35. ';
  36. $table .= "
  37. ';
  38. $table .= "
  39. ';
  40. $table .= "
  41. ';
  42. $table .= '
  43. ';
  44. }
  45. $table .= '
  46. ';
  47. $table .= '
  48. id标题电话地址审核状态内容留言时间
    ".$value['id'].'".$value['title'].'".$value['phone'].'".$value['address'].'".$value['ischeck'].'".$value['content'].'".substr($value['datetime'],0,11).'
    ';
  49. echo $table;
  50. ?>
  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. ';
  14. echo '
  15. ';
  16. echo '
  17. ';
  18. echo '
  19. ';
  20. echo '
  21. ';
  22. echo '
  23. ';
  24. echo '
  25. ';
  26. echo '
  27. ';
  28. echo '
  29. ';
  30. echo '
  31. ';
  32. echo '
  33. ';
  34. echo '
  35. ';
  36. echo '
  37. ';
  38. foreach ($content as $k => $v){
  39. echo "
  40. ";
  41. echo "
  42. ";
  43. echo "
  44. ";
  45. echo "
  46. ";
  47. echo "
  48. ";
  49. echo "
  50. ";
  51. echo "
  52. ";
  53. echo "
  54. ";
  55. echo "
  56. ";
  57. }
  58. echo '';
  59. echo '
  60. ';
  61. echo '
  62. 视频列表(index:在首页显示 lanmu:在视频页显示)
    序号用户uid显示位置文件名视频名视频介绍上传时间
    $k{$v['title']}{$v['phone']}{$v['address']}{$v['ischeck']}{$v['content']}{$v['datetime']}
    ';
  63. //var_dump($content);
  64. mysql_free_result($rs1);
  65. mysql_close($link);
  66. ?>

人气教程排行