<?php

 $conn = @mysqli_connect('localhost', 'root', '');
  if (!$conn)
  {
    die("Database Connection Failed" . mysqli_error($conn));
  }

  $select_db = mysqli_select_db($conn,'db');
  if (!$select_db)
  {
    die("Database Selection Failed" . mysqli_error($conn));
  }

   $conn1 = @mysqli_connect('192.168.2.117', 'webster', 'webster');
  if (!$conn1)
  {
    die("Database Connection Failed" . mysqli_error($conn1));
  }

  $select_db = mysqli_select_db($conn1,'realtimedata');
  if (!$select_db)
  {
    die("Database Selection Failed" . mysqli_error($conn1));
  }

  $date1 = "2018-10-31";
  $date2 = "2018-11-15";

  $basic_pay = 20000;

  
  $sql = "SELECT * from attendanceformatted where userid = 110036 and att_in between '$date1' and '$date2'";
  $query  = mysqli_query($conn,"SELECT * from emp_salary");
  $query1  = mysqli_query($conn1,$sql);
 $totalhours = 0;

 // while($row1=mysqli_fetch_array($query))
  	while($row=mysqli_fetch_array($query1))
 // {
  {
  /*  $salary           = $row1['basic_pay'];


  if(($salary >=1000) && ($salary <=1249.99)) {

     $total = ($salary - (36.30+100+137.50));

  } else if (($salary >=1250) && ($salary <=1749.99)) {
  $total = ($salary - (54.50+100+137.50));
  } else if (($salary >=1750) && ($salary <=2249.99)) {
  	$total = ($salary - (72.70+100+137.50));
  }else if (($salary >=2250) && ($salary <=2749.99)) {
  	$total = ($salary - (90.80+100+137.50));
  }else if (($salary >=2750) && ($salary <=3249.99)) {
  	$total = ($salary - (109.00+100+137.50));
  } else {
  	$total = 0;
  }*/

  echo "<br/>";

 $minTime = $row['att_in'];
 $maxTime = $row['att_out'];

  $ccdate = strtotime($minTime);
  $ccdate1 = strtotime($maxTime);

  /*$fdate = date('Y-m-d', $ccdate);
  $fdate1 = date('Y-m-d', $ccdate1); */

  echo $minTime;
  echo " "; 
  echo "<br/>";
  echo $maxTime;

  $diff = $ccdate - $ccdate1;
  $hours = abs($diff / ( 60 * 60 ));
  $hours = number_format($hours, 2);

  $totalhours += $hours;
  echo "<br/>";
  echo $totalhours;
echo "<br/>";


//}
}
echo "<br/>";
echo "--------total---------";
echo "<br/>";

$t1 = $basic_pay / 26.16;
$t2 = $t1 / 8.5;
$total1 = $totalhours * $t2;

echo "<br/>";
echo $totalhours;
echo "<br/>";
$total1 = number_format($total1, 2);
echo $total1;

?>