sandy1028 Posted June 4, 2008 Share Posted June 4, 2008 Name Start time End time A 2008-06-01 07:00:01 2008-06-01 07:10:01 0:0:10 A 2008-06-01 07:10:01 2008-06-01 09:50:01 0:0:10 A 2008-06-01 09:50:01 2008-06-01 10:00:01 0:0:10 B 2008-06-01 09:50:01 2008-06-01 10:00:01 0:0:10 B 2008-06-01 09:50:01 2008-06-01 10:00:01 0:0:10 Actually in the table it is displayed as the previous time is taken as the next Start time for the next row for the same name. How to aviod it. The code used is as below: while($result = mysql_fetch_array($row)) { $currentStatus = $result['status']; $currentTime = $result['timestamp']; $previousStatus = $previousStatus == '' ? $currentStatus : $previousStatus; $previoustime = $previoustime == '' ? $currentTime : $previoustime; //State change. if($previousStatus == $currentStatus) { $previousStatus=$currentStatus; continue; } $d = strtotime($currentTime) - strtotime($previoustime); array_push($records,"$result[2]#$ip[0]#$result[2]#$previoustime#$result[1]#$d#$_"); $previousStatus = $currentStatus; $previoustime=$currentTime; Actually in the above code the records are pushed into the array even if state change from 1 to 0. But I need only data from 0 to 1. How can I display it. How to push records into the array if status is always 0. If status doesnot change to 1 then 1st timestamp and last timestamp difference should be calculated. How to do it Link to comment https://forums.phpfreaks.com/topic/108663-iterate/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.