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)
);