Hi,
Here I am able to find differnence of only two rows.
Status is 0 or 1 for the row
and timestamp there is difference of every 10 minutes.
I have to calcutate differnce of timestamp from 0 and when the status changes to 1.
I have used the code below it takes too long time and it compares only between to rows.
$start_date = $_REQUEST["date1"];
$end_date = $_REQUEST["date2"];
if9$end_date != ""){
$res_date=mysql_query("select distinct(date(timestamp)) from `table1` where date(timestamp)>= '".$start_date."' and date(timestamp) <= '".$end_date."'");
}
else {
$res_date=mysql_query("select distinct(date(timestamp)) from updowntime where date(timestamp) = '".$start_date."'");
}
while($res2=mysql_fetch_array($res_date)){
$res_head="select distinct(head) from `table1` where date(timestamp)='".$res2[0]."' and status=0";
$res1 = mysql_query($res_head);
while($res = mysql_fetch_array($res1)){
$sql = "SELECT status,timestamp,head FROM `table1` WHERE head_node='".$res[0]."' and date(timestamp)='".$res2[0]."'";
$row = mysql_query($sql);
$previousStatus = '';
$currentStatus = '';
$previoustime='';
$currentTime='';
while($result = mysql_fetch_array($row))
{
$sql_ip="select ip from `table_ip` where head='".$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;
}
}
}