 |
|
โค๊ดชุดนี้ ผมจะดึงข้อมูล จาก .csv มานำเสนอเป็นตาราง table(html) แต่ผมไม่ให้ดึงข้อมูลจากแถวแรก และคอลัมแรกมา ต้องเขียนยังไงครับ
*****************************************
ตัวอย่าง data.csv
*****************************************
จำนวน....
1,เพศ,2556,2557,2557
2,ชาย,1,2,3
3,หญิง,4,5,6
ที่มา....
*****************************************
ผลเมือออกมาเป็น table ต้องการให้มันแสดงแบบนี้
*****************************************
Code
[table]
[tr]
[th]เพศ[/th]
[th]2555[/th]
[th]2556[/th]
[th]2557[/th]
[/tr]
[tr]
[td]ชาย[/td]
[td]1[/td]
[td]2[/td]
[td]3[/td]
[/tr]
[tr]
[td]หญิง[/td]
[td]4[/td]
[td]5[/td]
[td]6[/td]
[/tr]
[/table]
Code
<?php
echo "<html><body><div class='table-responsive'><table class='table' id='table_1'>\n\n";
$f = fopen("data.csv", "r");
while (($line = fgetcsv($f)) !== false) {
echo "<tr>";
foreach ($line as $cell) {
echo "<td>" . htmlspecialchars($cell) . "</td>";
}
echo "</tr>\n";
}
fclose($f);
echo "\n</table></div></body></html>";
?>
Tag : PHP, HTML/CSS, JavaScript
|
ประวัติการแก้ไข 2016-02-05 09:17:47
|
 |
 |
 |
 |
Date :
2016-02-05 09:14:04 |
By :
THAIBICYCLEBOARD |
View :
921 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |