|
 |
|
!!! ช่วยด้วยครับไปต่อไม่ถูกจริงๆ ใช้เงื่อนไขเวลาไปเช็ควันและเวลาจากข้อมูล Help me Please !!! |
|
 |
|
|
 |
 |
|
มีข้อมูลเก็บในไฟล์แต่ละบรรทัดเเป็นวัน เวลาและรหัสแบบนี้คั่นด้วยคอมมา อ่านข้อมูลมาทีละแถว
2011/01/24,23:10:52,emp001
2011/01/24,23:13:04,emp001
2011/01/24,23:40:18,emp002
2011/01/24,23:50:18,emp002
2011/01/24,23:50:12,emp001
2011/01/25,00:01:00,emp001
ผลลัพธ์สุดท้ายคือหาว่าแต่ละรหัสมีข้อมูลเริ่มต้นที่วันและเวลาใด ข้อมูลจบที่วันและเวลาใด ภายใต้เงื่อนไขว่าข้อมูลที่เข้ามาแต่ละแถวต้องมีเวลาไม่ต่างกันเกิน 20 นาที นับเป็น 1 ชุดข้อมูล แล้ว print ออกจอ แต่ถ้าข้อมูลที่เข้ามาใหม่เทียบเวลาแล้วเกิน 20 นาทีไปแล้วให้แสดงข้อมูลเดิมที่เก็บไว้ออกจอ เคลียร์ array ด้วย unset ซะแล้วสร้างข้อมูลชุดใหม่
ข้อมูล 1 ชุดเก็บเป็น array ลักษณะดังนี้ ให้คีย์เป็นแบบ Associative จากรหัส
result [รหัส][วันเริ่ม][เวลาเริ่ม][วันจบ][เวลาจบ]
[ 0 ][ 1 ][ 2 ][ 3 ][ 4 ]
เช่นตัวอย่างนี้คือต้องได้ข้อมูลออกมา 3 ชุดที่จอ
[emp001] [2011/01/24] [23:10:52] [2011/01/24] [23:13:04]
[emp002] [2011/01/24] [23:40:18] [2011/01/24] [23:50:18]
[emp001] [2011/01/24] [23:50:12] [2011/01/25] [00:01:00]
ผมให้ข้อมูลชุดแรกที่เข้าไปเป็นทั้ง [วันเริ่ม][เวลาเริ่ม][วันจบ][เวลาจบ] เลยพอข้อมูลชุดใหม่มาให้ add ไปที่[วันจบ][เวลาจบ]ก็พอ
<?php
$file = fopen("text.txt","r");
while (!feof($file)) {
$line = fgetcsv($file); //$line เป็น array
$key = line[2];
if(!array_key_exists($key,$array)) //ถ้า array ไม่มีค่าคีย์นี้มาก่อนให้สร้างใหม่
$result[$key] = array($key,line[0],line[1],line[0],line[1]);
if(array_key_exists($key,$array)){ //ถ้า array มีคีย์นี้แล้วแค่เพิ่มค่าเข้าไปอัพเดทในอินเด็ก [3] กับ [4]
$result[$key][3] = $line[0];
$result[$key][4] = $line[1]);
{
}
.......................................................
.......................................................
.......................................................
fclose($file);
?>
ทำไงต่อครับ ?
ผมมึนตี๊บเลยเพราะมันต้องใช้เงื่อนไข 20 นาที ไปเช็ควันและเวลาทั้ง 2 อย่างแล้วข้อมูลมันมีข้ามวันอีก
พยายามดูฟังก์ชันที่เว็บนี้เขียนอธิบายเกี่ยวกับพวกวันเวลาก็แล้วก็ยังไม่รู้จะใช้อย่างไร
https://www.thaicreate.com/php/php-date-time.html
งงไหมครับ ?
Tag : PHP, CakePHP

|
ประวัติการแก้ไข 2011-01-25 00:15:05 2011-01-25 00:20:12
|
 |
 |
 |
 |
Date :
2011-01-25 00:06:00 |
By :
trelnup |
View :
796 |
Reply :
0 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
|
|

|
Load balance : Server 01
|