|
 |
|
มีคำถามคับคือผมจะเอาค่าตัวแปรที่อยู่ในตาราง "customer2" ชื่อว่า ANAME เอาไปแทนที่ชื่อ Report.xls ยังไงครับ |
|
 |
|
|
 |
 |
|
ลองเก็บ content เป็นตัวแปร แล้วเรียก Header ทีหลังครับ
|
ประวัติการแก้ไข 2018-09-03 17:11:34
 |
 |
 |
 |
Date :
2018-09-03 16:47:28 |
By :
Jatmentz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พอมีตัวอย่างไหมครับ
|
 |
 |
 |
 |
Date :
2018-09-03 17:07:49 |
By :
HLEW |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คร่าวๆครับ
Code (PHP)
<?php
$content = '
<html>
<head>
<title>Customer</title>
</head>
<body background="bg-1.jpg"><center>
<br/>
<br/>
<table border="1" width="900" cellpadding="0" cellspacing="0">
<tr>
<th width="61">AID</th>
<th width="207">ANAME</th>
<th width="100">ASEX</th>
<th width="100">ABILITY</th>
<th width="129">AEMAIL</th>
<th width="103">ACOUNTRY</th>
<th width="96">ABUDGET</th>
</tr>
</table>
</body>
</html> ';
$aname = 'ANAME';
header("Content-Type: application/msexcel");
header('Content-Disposition: attachment; filename="'.$aname.'.xls"');
echo $content;
?>
|
 |
 |
 |
 |
Date :
2018-09-03 17:23:06 |
By :
Jatmentz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?php
$mysqli = mysqli_connect("localhost","root","03112530") or die("Error Connect to Database".$mysqli->connect_error););
$mysqli->select_db("mydatabase");
$mysqli->set_charset("utf8");
$strSQL="SELECT * FROM `customer2` ";
$objQuery = $mysqli->query($strSQL);
foreach ($objQuery as $value) {
$filename = $value["ANAME"];
}
header("Content-Type: application/msexcel");
header('Content-Disposition: attachment; filename="'.$filename.'"'); //จะให้มันแสดงแทนที่ Report ยังไงครับ
?>
<html>
<head>
<title>Customer</title>
</head>
<body background="bg-1.jpg"><center>
<br/>
<br/>
<table border="1" width="900" cellpadding='0' cellspacing='0'>
<tr>
<th width="61">AID</th>
<th width="207">ANAME</th>
<th width="100">ASEX</th>
<th width="100">ABILITY</th>
<th width="129">AEMAIL</th>
<th width="103">ACOUNTRY</th>
<th width="96">ABUDGET</th>
</tr>
<?php
foreach ($objQuery as $value) {
echo "<tr>" .
"<td align='center'>" . $value["AID"]. "</td>" .
"<td align='center'>" . $value["ANAME"] . "</td>" .
"<td align='center'>" . $value["ASEX"] . "</td>" .
"<td align='center'>" . $value["ABILITY"] . "</td>" .
"<td align='center'>" . $value["AEMAIL"] . "</td>" .
"<td align='center'>" . $value["ACOUNTRY"] . "</td>" .
"<td align='center'>" . $value["ABUDGET"] . "</td>" .
"</tr>";
}
$mysqli->close();
?>
</table>
</body>
</html>
สลับที่กันเฉยๆ+เปลี่ยนเป็น mysqli ให้เผื่อเป็นแนวทาง
|
ประวัติการแก้ไข 2018-09-03 17:44:46
 |
 |
 |
 |
Date :
2018-09-03 17:43:35 |
By :
ciockie |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองดู php spreadsheet ไหม...ใช้ง่ายนะ อาจจะช่วยได้
|
 |
 |
 |
 |
Date :
2018-09-04 10:28:40 |
By :
apisitp |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|