|
 |
|
รบกวนอีกรอบค่ะ K.xbeginner01 โค๊ดด้านบนนั้นลองทำมาใหม่แล้วค่ะ ผลลัพธ์จากการคำนวณผลนั้นถูกต้อง |
|
 |
|
|
 |
 |
|
ขอคำแนะนำหน่อยนะคะ
|
 |
 |
 |
 |
Date :
2010-03-04 15:47:36 |
By :
plezaza |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เป็นไปได้อย่าทำโค้ดเป็นรูปได้ไม มันดึงมาแก้ไม่ได้
ต่อจากกระทู้ก่อนหน้าน่ะครับ
Code (PHP)
$init= true;
while($res=odbc_fetch_array($execute_promote)){
if($init){
$init=false;
}else{
$diff .=diffDateTime($x,$res['date']);
}
$x=$res['date'];
}
$diff .=diffDateTime($x,date('Y-m-d'));
echo "<table border=1>";
echo "<tr><td>เวลาการทำงาน</td><td>วันที่ที่เปลี่ยนงาน</td></tr>";
echo $diff;
echo "</table>";
function diffDateTime($date1,$date2){
$diff =abs(strtotime($date1)-strtotime($date2));
$years = floor($diff / 31536000);
$months = floor(($diff % 31536000) / 2592000);
return "<tr><td> $years ปี $months เดือน </td><td>$date1</td></tr>";
}
|
 |
 |
 |
 |
Date :
2010-03-04 17:18:17 |
By :
xbeginner01 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
K.xbeginner01
พอดีว่า echo ค่าออกมาแล้วได้ถูกต้องค่ะ ว่าแสดงค่าในตารางไม่ถูกอ่ะคะ แนะนำหน่อยนะ
ลืมบอกว่าเพิ่งเริ่มหัดเขียนอะคะเลยยังไม่ค่อยเป็นซะเท่าไร ยังไงก็ขอบคุณมากนะคะที่แนะนำ
ค่าที่ echo

ค่าในตาราง

code
Code (PHP)
<?
$n=1;
$init = true ;
while ($res=odbc_fetch_array($execute_promote)){
if($init){
$init = false ;
}else{
$diff= diffDateTime($x,$res['AppvDate']) ;
echo $diff ;
}
$x=$res['AppvDate'];
$AppvDate = odbc_result($execute_promote,"AppvDate");
$AppvDate = ereg_replace("00:00:00.000","",$AppvDate);
$LastPostName=odbc_result($execute_promote,"LastPostName");
$LastPostName = ereg_replace("<คลัง>","",$LastPostName);
$LastPostName = ereg_replace("<ขาย>","",$LastPostName);
$newpostname = odbc_result($execute_promote,"newpostname");
$newpostname = ereg_replace("<คลัง>","",$newpostname);
$newpostname = ereg_replace("<ขาย>","",$newpostname);
?>
<tr bgcolor="#CCFFCC"class="font14">
<td align="left"><?=$LastPostName?></td>
<td align="center"><?=odbc_result($execute_promote,LastBrchName)?></td>
<td align="center"><?=odbc_result($execute_promote,LastDeptName)?></td>
<td align="center"><?=odbc_result($execute_promote,LastLevl)?></td>
<td align="left"><?=$newpostname?></td>
<td align="center"><?=odbc_result($execute_promote,newBrchName)?></td>
<td align="center"><?=odbc_result($execute_promote,newDeptName)?></td>
<td align="center"><?=odbc_result($execute_promote,newLevl)?></td>
<td align="center"><?=$diff ?> </td>
<td align="center"><?=$AppvDate?></td>
</tr>
<? $n++; }
$diff = diffDateTime($x,date('Y-m-d'));
echo $diff ;
?>
</table>
|
 |
 |
 |
 |
Date :
2010-03-05 11:23:42 |
By :
plezaza |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?
$n=1;
$init = true ;
while ($res=odbc_fetch_array($execute_promote)){
if($init){
$init = false ;
}else{
$diff= diffDateTime($x,$res['AppvDate']) ;
$AppvDate = odbc_result($execute_promote,"AppvDate");
$AppvDate = ereg_replace("00:00:00.000","",$AppvDate);
$LastPostName=odbc_result($execute_promote,"LastPostName");
$LastPostName = ereg_replace("<คลัง>","",$LastPostName);
$LastPostName = ereg_replace("<ขาย>","",$LastPostName);
$newpostname = odbc_result($execute_promote,"newpostname");
$newpostname = ereg_replace("<คลัง>","",$newpostname);
$newpostname = ereg_replace("<ขาย>","",$newpostname);
$LastBrchName=odbc_result($execute_promote,LastBrchName);
$LastDeptName=odbc_result($execute_promote,LastDeptNamej);
$LastLevl=odbc_result($execute_promote,LastLevl);
$newBrchName=odbc_result($execute_promote,newBrchName);
$newDeptName=odbc_result($execute_promote,newDeptName);
$newLevl=odbc_result($execute_promote,newLevl);
?>
<tr bgcolor="#CCFFCC"class="font14">
<td align="left"><?=$LastPostName?></td>
<td align="center"><?=$LastBrchName?></td>
<td align="center"><?=$LastDeptName?></td>
<td align="center"><?=$LastLevl?></td>
<td align="left"><?=$newpostname?></td>
<td align="center"><?=$newBrchName?></td>
<td align="center"><?=$newDeptName?></td>
<td align="center"><?=$newLevl?></td>
<td align="center"><?=$diff ?> </td>
<td align="center"><?=$AppvDate?></td>
</tr>
<?
}
$x=$res['AppvDate'];
$n++;
}
$diff = diffDateTime($x,date('Y-m-d'));
?>
<tr bgcolor="#CCFFCC"class="font14">
<td align="left"><?=$LastPostName?></td>
<td align="center"><?=$LastBrchName?></td>
<td align="center"><?=$LastDeptName?></td>
<td align="center"><?=$LastLevl?></td>
<td align="left"><?=$newpostname?></td>
<td align="center"><?=$newBrchName?></td>
<td align="center"><?=$newDeptName?></td>
<td align="center"><?=$newLevl?></td>
<td align="center"><?=$diff ?> </td>
<td align="center"><?=$AppvDate?></td>
</tr>
</table>
<?php
function diffDateTime($date1,$date2){
$diff =abs(strtotime($date1)-strtotime($date2));
$years = floor($diff / 31536000);
$months = floor(($diff % 31536000) / 2592000);
return "$years ปี $months เดือน";
}
?>
|
 |
 |
 |
 |
Date :
2010-03-05 11:56:23 |
By :
xbeginner01 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เวลาการทำงานขึ้นถูกต้องแล้ว แต่วันที่เปลี่ยนงานหายไปเรคคอร์ดหนึ่งคะ คือเรคคอร์ดแรกอ่ะ และเรคคอร์ดหลังผิดค่ะ
สิงที่ต้องการคือ
0 ปี 1 เดือน 2008-03-01
0 ปี 9 เดือน 2008-04-01
0 ปี 8 เดือน 2009-01-01
0 ปี 6 เดือน 2009-09-01
แต่ผลลัพธ์จากโค๊ดด้านบนได้แบบนี้อะค่ะ
0 ปี 1 เดือน 2008-04-01
0 ปี 9 เดือน 2009-01-01
0 ปี 8 เดือน 2009-09-01
0 ปี 6 เดือน 2009-09-01
|
 |
 |
 |
 |
Date :
2010-03-05 13:22:59 |
By :
plezaza |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พอดีว่าเวลางานออนไม่ได้อะค่ะ รบกวนนิดนะคะ
|
 |
 |
 |
 |
Date :
2010-03-05 13:49:16 |
By :
plezaza |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อ่อ พอจะเข้าใจที่ผิดแล้วครับ :)
syntax ดูมั่วๆแต่ต้นแหล่ะเลยเลยตามเลยไป ขอเวลาแก้แปปครับ
|
 |
 |
 |
 |
Date :
2010-03-05 17:02:10 |
By :
xbeginner01 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ก่อนอื่นน่ะครับ ต้องเปลี่ยน query ให้ผมใหม่ก่อน ให้เรียกจากเวลาล่าสุดไล่ลงไปต่ำสุด
อันเก่าเรียกจากน้อยสุดมาล่าสุด
2008-03-01
2008-04-01
2009-01-01
2009-09-01
ให้ query >> select ...... order by AppvDate DESC
อันใหม่จะได้จากล่าสุดไปน้อยสุด
2009-09-01
2009-01-01
2008-04-01
2008-03-01
Code (PHP)
$x=date('Y-m-d');
$n=1;
$bak='';
while (odbc_fetch_row($execute_promote,$n)){
$AppvDate = odbc_result($execute_promote,"AppvDate");
$AppvDate = ereg_replace("00:00:00.000","",$AppvDate);
$LastPostName=odbc_result($execute_promote,"LastPostName");
$LastPostName = ereg_replace("<คลัง>","",$LastPostName);
$LastPostName = ereg_replace("<ขาย>","",$LastPostName);
$newpostname = odbc_result($execute_promote,"newpostname");
$newpostname = ereg_replace("<คลัง>","",$newpostname);
$newpostname = ereg_replace("<ขาย>","",$newpostname);
$LastBrchName=odbc_result($execute_promote,LastBrchName);
$LastDeptName=odbc_result($execute_promote,LastDeptNamej);
$LastLevl=odbc_result($execute_promote,LastLevl);
$newBrchName=odbc_result($execute_promote,newBrchName);
$newDeptName=odbc_result($execute_promote,newDeptName);
$newLevl=odbc_result($execute_promote,newLevl);
$diff=diffDateTime($AppvDate,$x);
$data=<<<HTML
<tr bgcolor="#CCFFCC"class="font14">
<td align="left">$LastPostName</td>
<td align="center">$LastBrchName</td>
<td align="center">$LastDeptName</td>
<td align="center">$LastLevl</td>
<td align="left">$newpostname</td>
<td align="center">$newBrchName</td>
<td align="center">$newDeptName</td>
<td align="center">$newLevl</td>
<td align="center">$diff </td>
<td align="center">$AppvDate</td>
</tr>
HTML;
$bak=$data.$bak; // จุดสำคัญคือตรงนี้ มีการ เก็บค่าตัวแปรไว้ก่อนโดยเรียงจากน้อยสุดมามากสุด
$x=$d;
$n++;
}
echo "<table>";
echo $bak;
echo "</table>";
function diffDateTime($date1,$date2){
$diff =abs(strtotime($date1)-strtotime($date2));
$years = floor($diff / 31536000);
$months = floor(($diff % 31536000) / 2592000);
return "$years ปี $months เดือน ";
}
ทดสอบดูก่อนน่ะครับ ยังไม่ได้ทดสอบ แต่ถ้าเข้าใจหลักการก็สามารถแก้ไขเองได้แล้วครับ
|
 |
 |
 |
 |
Date :
2010-03-05 17:30:34 |
By :
xbeginner01 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|