PDA

View Full Version : การส่งออกข้อมูลเข้าสู่ Ms Excel ด้วย PHP



attaporn11
05-12-2006, 08:09 AM
การส่งออกเข้า Ms Excel จะส่งออกในรูปแบบของไฟล์ csv และสามารถเปิดด้วย
โปรแกรม Microsoft Excel ลองมาดูตัวอย่างกันหน่อยนะครับ

ชื่อฐานข้อมูล mydatabase
รายละเอียดของตาราง

CREATE TABLE `testing` (
`id` int(3) NOT NULL auto_increment,
`question` varchar(100) NOT NULL default '',
`c1` varchar(100) NOT NULL default '',
`c2` varchar(100) NOT NULL default '',
`c3` varchar(100) NOT NULL default '',
`c4` varchar(100) NOT NULL default '',
`answer` int(1) NOT NULL default '0',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=11 ;

#
# dump ตาราง `testing`
#

INSERT INTO `testing` VALUES (1, 'ข้อที่ 1', 'ตัวเลือกที่ 1', 'ตัวเลือกที่ 2', 'ตัวเลือกที่ 3', 'ตัวเลือกที่ 4', 1);
INSERT INTO `testing` VALUES (2, 'ข้อที่ 2', 'ตัวเลือกที่ 1', 'ตัวเลือกที่ 2', 'ตัวเลือกที่ 3', 'ตัวเลือกที่ 4', 2);
INSERT INTO `testing` VALUES (3, 'ข้อที่ 3', 'ตัวเลือกที่ 1', 'ตัวเลือกที่ 2', 'ตัวเลือกที่ 3', 'ตัวเลือกที่ 4', 3);
INSERT INTO `testing` VALUES (4, 'ข้อที่ 4', 'ตัวเลือกที่ 1', 'ตัวเลือกที่ 2', 'ตัวเลือกที่ 3', 'ตัวเลือกที่ 4', 4);
INSERT INTO `testing` VALUES (5, 'ข้อที่ 5', 'ตัวเลือกที่ 1', 'ตัวเลือกที่ 2', 'ตัวเลือกที่ 3', 'ตัวเลือกที่ 4', 4);
INSERT INTO `testing` VALUES (6, 'ข้อที่ 6', 'ตัวเลือกที่ 1', 'ตัวเลือกที่ 2', 'ตัวเลือกที่ 3', 'ตัวเลือกที่ 4', 3);
INSERT INTO `testing` VALUES (7, 'ข้อที่ 7', 'ตัวเลือกที่ 1', 'ตัวเลือกที่ 2', 'ตัวเลือกที่ 3', 'ตัวเลือกที่ 4', 2);
INSERT INTO `testing` VALUES (8, 'ข้อที่ 8', 'ตัวเลือกที่ 1', 'ตัวเลือกที่ 2', 'ตัวเลือกที่ 3', 'ตัวเลือกที่ 4', 1);
INSERT INTO `testing` VALUES (9, 'ข้อที่ 9', 'ตัวเลือกที่ 1', 'ตัวเลือกที่ 2', 'ตัวเลือกที่ 3', 'ตัวเลือกที่ 4', 2);
INSERT INTO `testing` VALUES (10, 'ข้อที่ 10', 'ตัวเลือกที่ 1', 'ตัวเลือกที่ 2', 'ตัวเลือกที่ 3', 'ตัวเลือกที่ 4', 3);


Sample1.php

**Hidden Content: Check the thread to see hidden data.**

tatchadol
10-01-2009, 12:43 AM
หาตั้งนาน ขอบคุณมากนะครับ ไม่ได้อันนี้แย่เลย

guy852
10-01-2009, 05:15 AM
ออกมาเป็น csv ใช้โปรแกรมพวกโลตัสเปิดก็ได้นะครับ

จริงๆแล้วตัว phpmyadmin ก็ทำได้นะครับ :lol: