 |
อยากแก้ไข จาก datetime เป็น date ค่ะ ^^ ด้านบนคือ คำสั่ง export ค่าใน excel นะคะ คือว่า เนยมีปัญหาที่ว่า พอ ดึงข้อมูลของ project_start_date |
|
 |
|
|
 |
 |
|
Code (PHP)
function exportexcel($newdate1,$newdate2){
// Connect database.
mysql_connect("localhost","root","admin");
mysql_select_db("project_2");
// Get data records from table.
$result=mysql_query(
"select projects.project_id,companies.company_name,projects.project_name,projects.project_target_budget,projects.project_start_date,projects.project_end_date, projects.project_actual_end_date,users.user_username
from projects , users ,companies
where projects.project_owner = users.user_id and projects.project_company = companies.company_id and projects.project_status ='2' and projects.project_actual_end_date between '$newdate1' and '$newdate2' order by projects.project_actual_end_date");
// Functions for export to excel.
function xlsBOF() {
echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
return;
}
function xlsEOF() {
echo pack("ss", 0x0A, 0x00);
return;
}
function xlsWriteNumber($Row, $Col, $Value) {
echo pack("sssss", 0x203, 14, $Row, $Col, 0x0);
echo pack("d", $Value);
return;
}
function xlsWriteLabel($Row, $Col, $Value ) {
$L = strlen($Value);
echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L);
echo $Value;
return;
}
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
$strfilename = header("Content-Disposition: attachment;filename=project.xls ");
header("Content-Transfer-Encoding: binary ");
xlsBOF();
/*
Make a top line on your excel sheet at line 1 (starting at 0).
The first number is the row number and the second number is the column, both are start at '0'
*/
// Make column labels. (at line 1)
xlsWriteLabel(0,0,"Project ID");
xlsWriteLabel(0,1,"Project Company");
xlsWriteLabel(0,2,"Project Name");
xlsWriteLabel(0,3,"Budget");
xlsWriteLabel(0,4,"Start Date");
xlsWriteLabel(0,5,"End Date");
xlsWriteLabel(0,6,"Acutual Date");
xlsWriteLabel(0,7,"Owner");
//xlsWriteLabel(0,8,"Value");
$xlsRow = 1;
// Put data records from mysql by while loop.
while($row=mysql_fetch_array($result)){
xlsWriteLabel($xlsRow,0,$row['project_id']);
xlsWriteLabel($xlsRow,1,$row['company_name']);
xlsWriteLabel($xlsRow,2,$row['project_name']);
xlsWriteNumber($xlsRow,3,$row['project_target_budget']);
xlsWriteLabel($xlsRow,4,$row['project_start_date']);
xlsWriteLabel($xlsRow,5,$row['project_end_date']);
xlsWriteLabel($xlsRow,6,$row['project_actual_end_date']);
xlsWriteLabel($xlsRow,7,$row['user_username']);
//xlsWriteLabel($xlsRow,8,$row['value']);
$xlsRow++;
}
xlsEOF();
exit();
}
ด้านบนคือ คำสั่ง export ค่าใน excel นะคะ คือว่า เนยมีปัญหาที่ว่า พอ ดึงข้อมูลของ project_start_date และ project_end_date ออกมาแสดง แล้วค่ะ มันอยู่ในรูปแบบของ datetime (2010-07-02 00:00:00) แบบนี้อ่ะค่ะ
แต่ว่าอยากได้แบบ date แทน จะต้องเพิ่มโค้ดในส่วนไหนบ้างคะ รบกวนอีกรอบนะคะ ^^
Tag : - - - -
|
|
 |
 |
 |
 |
Date :
2010-07-02 15:03:47 |
By :
noey |
View :
1068 |
Reply :
7 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
น่าจะพอเป็นประโยชน์ น่ะ ครับ
<?php
// date time
$_arr_date_time = array();
$_date_time = date('Y-m-d h:i:s');
$_arr_date_time = explode(' ', $_date_time);
print_r($_arr_date_time);
// output: Array ( [0] => 2010-07-02 [1] => 09:14:55 )
// or
list($_date, $_time) = explode(' ', $_date_time);
// ouput:
echo $_date,$_time;
// or
$_date_create = date_create( $_date_time); // PHP 5 ^
$_date_format = date_format($_date_create, 'Y-m-d'); // PHP 5 ^
// output:
echo $_date_format;
?>
|
 |
 |
 |
 |
Date :
2010-07-02 20:17:01 |
By :
mrjidjad |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองอ่านดูฟังก์ชั่น date_format ของ mysql ดูครับ จะได้ผลลัพธ์ออกมาตามที่ต้องการเลย ไม่ต้องใช้ php ทำอีกขั้นตอนนึง
|
 |
 |
 |
 |
Date :
2010-07-03 00:48:31 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณทุกคนนะคะ เดี๋ยวลองไปทำดูก่อน แล้วจะมารายงานผลค่ะ ^^
|
 |
 |
 |
 |
Date :
2010-07-03 01:02:24 |
By :
noey |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าแก้ปัญหาที่ปลายเหตุ ง่ายๆๆเลยครับ ตัดสติง substr(); เอาเลย จบ
|
 |
 |
 |
 |
Date :
2010-07-03 10:17:05 |
By :
aimoomoo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองทำแบบ dateformat แล้วค่ะ ทำไม่ได้ค่ะ 
|
 |
 |
 |
 |
Date :
2010-07-03 15:23:52 |
By :
noey |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณทุกคนเลยนะคะ ทำได้แล้วค่ะ เนยใช้แบบ substr(); เอาค่ะ ขอบคุณนะคะ 
|
 |
 |
 |
 |
Date :
2010-07-05 08:46:05 |
By :
noey |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|