Hi,
I have a code to find the timestamp when the status changes from 0 to 1. But my problem is when the status doesnot change to 1 I have to calculate the time from first timestamp to now().
Please help me
$sql = "SELECT status,timestamp,name FROM table WHERE name='".$res[0]."' and date(timestamp)='".$res2[0]."'";
$row = mysql_query($sql);
$previousStatus = '';
$currentStatus = '';
$previoustime='';
$currentTime='';
while($result = mysql_fetch_array($row))
{
$sql_ip="select ifnull(ip,'--') from table1 where name='".$res[0]."'";
$sql_ip1=mysql_query($sql_ip);
while($ip=mysql_fetch_array($sql_ip1)){
if($ip[0]==""){
$ip[0]='--';
}
$currentStatus = $result['status'];
$currentTime = $result['timestamp'];
$previousStatus = $previousStatus == '' ? $currentStatus : $previousStatus;
$previoustime = $previoustime == '' ? $currentTime : $previoustime;
if($previousStatus == $currentStatus)
{
$previousStatus=$currentStatus;
$previoustime=$currentTime;
continue;
}
$d = strtotime($currentTime) - strtotime($previoustime);
array_push($records,"$result[2]#$ip[0]#$result[2]#$previoustime#$result[1]#$d");
$previousStatus = $currentStatus;
$previoustime=$currenttime;
}