PHP如何查询MySQL数据页面并输出内容到页面,并另存为CSV或EXCEL文件
来源:互联网 发布:php怎么找工作 编辑:程序博客网 时间:2024/06/18 14:26
<? header("Content-type:text/html;charset=utf-8"); /** * mysql connection configure * 2016-04-09 * Ron */ $ychat_host = "localhost"; $ychat_username = "root"; $ychat_password = ""; $ychat_database = "talk"; $con = mysql_connect($ychat_host,$ychat_username,$ychat_password) or die ("connection MySQL failed!"); //select database mysql_select_db($ychat_database,$con); //sql $sql = "select id,username,password,sex,address,country from userinfo "; //set encode mysql_query("set names utf8"); //query results $result = mysql_query($sql) or die ("query failed! "+mysql_error); //count $count = mysql_num_rows($result); // number of rows $rows = mysql_affected_rows($con); // Number of colums $colums = mysql_num_fields($result); if($count==0){ echo "no result!"; }else{ echo "total:".$count; echo "<table border='1' style='border-collapse:collapse;border:1px solid red;' cellpadding='1' cellspacing='1'>"; echo "<tr>"; for($i = 0;$i < $colums; $i++){ $fieldName = mysql_field_name($result, $i); echo "<th>$fieldName</th>"; } echo "</tr>"; while($row=mysql_fetch_row($result)){ echo "<tr>"; for($i=0; $i<$colums; $i++){ echo "<td>$row[$i]</td>"; } echo "</tr>"; } echo "</table>"; } // release result set mysql_free_result($result); //close connection mysql_close($con);?>
<? header("Content-type:text/html;charset=utf-8"); /** * mysel connection configure * 2016-04-09 * Ron */ $ychat_host = "localhost"; $ychat_username = "root"; $ychat_password = ""; $ychat_database = "talk"; $con = mysql_connect($ychat_host,$ychat_username,$ychat_password) or die ("connection MySQL failed!"); //select database mysql_select_db($ychat_database,$con); //sql $sql = "select id,username,password,sex,address,country from userinfo"; //set encode mysql_query("set names utf8"); //query results $result = mysql_query($sql) or die ("query failed! "+mysql_error); //count $count = mysql_num_rows($result); if($count==0){ echo "no result!"; }else{ echo "<table border='1' style='border-collapse:collapse;border:1px solid red;' cellpadding='1' cellspacing='1'>"; echo "<tr>"; echo "<th>id</th><th>用户名</th><th>性别</th><th>地址</th><th>国家</th>"; echo "</tr>"; while ($userinfo = mysql_fetch_array($result)) { $id= $userinfo["id"]; $name= $userinfo["username"]; $sex= $userinfo["sex"]; $address= $userinfo["address"]; $country= $userinfo["country"]; echo "<tr>"; echo "<td>$id</td><td>$name</td><td>$sex</td><td>$address</td><td>$country</td>"; echo "</tr>"; } echo "</table>"; } // release result set mysql_free_result($result); //close connection mysql_close($con);?>
阅读全文
0 0
- PHP如何查询MySQL数据页面并输出内容到页面,并另存为CSV或EXCEL文件
- 在不知内容的情况下获取Excel表的内容并输出到JSP页面
- 通过连接读取页面内容并输出到本地
- 获取web目录下的文件并输出内容到页面
- PHP导出MySQL数据到Excel或者CSV文件
- Ecshop中是如何将查询到的数据传送到页面并显示的呢?
- 数据导入到excel 并显示在页面
- PHP读取Excel文件的内容并写入Mysql数据库
- Powershell调用Excel批量读取指定单元格数据并输出csv结果文件
- PHP导出MySQL数据到CSV文件
- Java读取csv文件并将内容插入到数据库
- Java读取csv文件并将内容插入到数据库
- php 发起 post http请求 ,并传body内容 到另一个php页面
- Excel中使用VBA筛选数据并将结果另存为新的EXCEL文件
- c# 使用FileStream打开并清空文件、将一文件内容另存为到新文件
- c# 使用FileStream打开并清空文件、将一文件内容另存为到新文件
- PHP抓取Json页面并写入文件
- 将Excel或CSV文件中的数据导出到DataSet
- npm
- POJ1321-回溯+DFS
- caffe openpose/Realtime Multi-Person 2D Pose Estimation using Part Affinity Fields配置
- 【已解决】开发模式下,微信公众号自定义菜单显示不全
- UnicodeDecodeError: ‘ascii’ codec……not in range(128)
- PHP如何查询MySQL数据页面并输出内容到页面,并另存为CSV或EXCEL文件
- https协议和http的区别。
- 【indeed】C
- DOM
- 搜索 F
- 进程学习10--syslog记录调试信息
- 2017年5月31日网站日志调研
- 安装beautifulsoup4 时出现 ImportError: cannot import name 'beautifulsoup'
- bzoj 1477 青蛙的约会 拓展欧几里得(详细解析)