I am trying to generator the report based on login datetime and logout datetime. Here is my code:
while (strtotime($begin_date) <= strtotime($end_date)){
foreach($us AS $title) {
$stmt="SELECT event,event_epoch,event_date,campaign_id,user_group,session_id,server_ip,extension,computer_ip,phone_login,phone_ip from ".$user_table." where user = '$title' and event_date >= '$begin_date $begin_time' and event_date <= '$begin_date $end_time' order by user_id asc;";
$rslt=mysql_to_mysqli($stmt, $link);
$events_to_print = mysqli_num_rows($rslt);
while ($events_to_print > $o){
$sel1 = "select full_name from users where user = '$title'";
$res1 = mysqli_query($link,$sel1);
$row1 = mysqli_fetch_array($res1);
if (preg_match("/LOGIN/i", $row[0])){
$date = date('Y-m-d');
$MAIN.="<tr $bgcolor>";
$MAIN.="<td><font size=2>$begin_date</td>";
$MAIN.="<td align=right><font size=2> $row1[0] </td>\n";
$MAIN.="<td align=right><font size=2> $title </td>\n";
$MAIN.="<td align=right><font size=2> $row[3] </td>\n";
$MAIN.="<td align=right><font size=2> $row[2] </td>\n";
$val = $row[2];
} else {
$MAIN.="<td><font size=2>$row[2]</td>";
$MAIN.="<td align=right><font size=2> $row1[2] </td>\n";
$MAIN.="<td align=right><font size=2> $row[1]</td>\n";
$MAIN.="<td align=right><font size=2> $row1[3] </td>\n";
$MAIN.="<td align=right><font size=2> $row12[2] </td>\n";
}
}
}
In the above code if codition and else codition two are executing both times. result is like this:
Date AgentName AgentId CAMPAIGN LOGINTIME LOGOUTTIME COUNT LASTCALL
2020-04-22 ABC 1 test 2020-04-22 2020-04-22 12 No
14:20:00 14:25:10
2020-04-22 XYZ 3 test12 2020-04-22 2020-04-22 6 No
14:50:00 15:25:10
2020-04-22 ABC 1 test 2020-04-22 2020-04-22 120 NO
19:20:00 19:10:10
2020-04-22 190 YES
14:20:00
2020-04-22 ABC 1 test 2020-04-22 2020-04-22 Yes No
14:20:00 14:25:10
In the above code 2020-04-22 14:20:00 190 YES
this is belongs to logout but that is display in login place bez there is no login detailsin, in this case what I need to do.
Expected output like this:
Date AgentName AgentId CAMPAIGN LOGINTIME LOGOUTTIME COUNT LASTCALL
2020-04-22 ABC 1 test 2020-04-22 2020-04-22 12 No
14:20:00 14:25:10
2020-04-22 XYZ 3 test12 2020-04-22 2020-04-22 6 No
14:50:00 15:25:10
2020-04-22 ABC 1 test 2020-04-22 2020-04-22 120 NO
19:20:00 19:10:10
2020-04-22 190 YES
14:20:00
2020-04-22 ABC 1 test 2020-04-22 2020-04-22 Yes No
14:20:00 14:25:10
Note :DB data like this:
event eventdate
LOGIN 2020-04-22
12:15:00
LOGOUT 2020-04-22
12:30:10
LOGIN 2020-04-22
12:15:00
LOGOUT 2020-04-22
13:15:10
LOGOUT 2020-04-22
14:15:00
LOGIN 2020-04-22
15:25:00