php显示表格
⑴ php请问我需要在页面上显示 EXCEL表格,并且能下载怎么做呢
$retdata=array(); //内容 //二维数组
$filename= "文件.csv";
//生成头文件
$now = gmdate("D, d M Y H:i:s");
header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
header("Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate");
header("Last-Modified: {$now} GMT");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Disposition: attachment;filename={$filename}");
header("Content-Transfer-Encoding: binary");
//生成表格
$title=array('"金额"','"会员"','"余额"'); //每列的标题
$str=implode(',',$title) . PHP_EOL;
foreach ($retdata as $row) {
// print_r($row);
$str_arr = array();
foreach ($row as $column) {
$str_arr[] = '"' . str_replace('"', '""', $column) . '"';
}
$str.=implode(',', $str_arr) . PHP_EOL;
}
print(chr(0xEF).chr(0xBB).chr(0xBF));
echo $str;
⑵ 如何编写php网页代码,让查询到的成绩显示在表格里
action 到 doing.php 就要用post或者get之后连接数据库,插入数据并显示数据,下面是个小例子也有注释
<?php
$data['class'] = $_POST['class'] + 0;
$data['name'] = trim($_POST['name']);
$data['math'] = $_POST['math'] + 0;
$data['chemistry'] = $_POST['chemistry'] + 0;//以下的自己写
/*连接数据库 插入数据*/
$conn = mysql_connect('url','username','password');
$sql = 'use db_name';
mysql_query($sql,$conn);
//这个其实可以封装成一个更好的丢向方法就不写了
foreach($data as $k=>$v){
$sql = 'insert into db('.$k.')value("'.$v.'")';
mysql_query($sql,$conn);
}
/*取出数据并打印*/
$sql = 'select class,name,math,chemistry from table_name order by class';
$res = mysql_query($sql,$conn);
echo '<table id="score"><tr><td>班级</td><td>名字</td><td>数学</td><td>化学</td></tr>';
while($row = mysql_fetch_assoc($res)){//取关系数组,打印
echo '<tr><td>'.$row['class'].'</td><td>'.$row['name'].'</td><td>'.$row['math'].'</td><td>'.$row['chemistry'].'</td></tr>';
}
echo '</table>';?>
⑶ php瀵煎嚭鐢熸垚excel琛ㄦ牸鍑犵嶆柟娉曚粙缁
php header("Content-type:application/vnd.ms-excel"); header("Content-Disposition:attachment;filename=test_data.xls");$tx=钬栾〃澶粹; echo $tx."nn"; //杈揿嚭鍐呭瑰备笅锛 echo "濮揿悕"."t"; echo "骞撮缎"."t"; echo "瀛﹀巻"."t";echo "n";echo "寮犱笁"."t"; echo "25"."t"; echo "链绉"."t"; >濡傛灉浣犱竴瀹氲佽緭鍏xls镙囧嗳镄别xcel鏂囦欢鍙鍙傝冧笅闱㈡柟娉/** * 杈揿嚭XLS镄勫ご淇℃伅 * 娉锛氢娇鐢ㄦゅ嚱鏁板墠钖庨兘涓嶅簲链変换浣曟暟鎹杈揿嚭
⑷ 怎样用php制作表格
1、建立一个数组,取名为$ShuZu,举例数组的内容是学生的信息,包括姓名、性别和年龄。
$ShuZu = array
(
array("姓名","性别","年龄"),
array("张三","男",13),
array("里斯","女",12),
array("王五","男",15)
);