title: show total number of leave from table
body: <p>I've two tables called work_details and holy_days. </p>
  
  <p>Holy_days table contains a row for each holiday in each year. 
  work_details contains a row for each day's work report for each employee. </p>
  
  <p>I want to get the leave report (yearly &amp; monthly) of all employees. </p>
  
  <p>I want to show how many days of leave they took per year and also per month (with dates)</p>
  
  <p>Calculate leave days except saturday, sunday and the dates in holy_days table. Am using the following code, but this is not working properly..anybody plz help.</p>
  
  <pre><code>if ($request-&gt;isPost()) {
      $sdate1 = $request-&gt;get('txt_date1','post');
      $d1=explode('/', $sdate1);
      $sdate= $d1['2'].'-'.$d1['0'].'-'.$d1['1'];
      $edate1 = $request-&gt;get('txt_date2','post');
      $d2=explode('/', $edate1);
      $edate= $d2['2'].'-'.$d2['0'].'-'.$d2['1'];
  $count=dates_between($emp_id,$sdate,$edate);
  
  echo $count;
  
    }
  
  
  function dates_between($emp_id,$start_date, $end_date = false)
   {
       if ( !$end_date )
       {
           $end_date = date("Y-m-d");
       }
  
       $test_date = $start_date;
       $day_incrementer = 1;
       $count_leaves=0;
       $flag=0;
       echo "SELECT DISTINCT date FROM `work_details` WHERE  employee_id='".$emp_id."' and date between '".$start_date."' and '".$end_date."'";
   $work_res = mysql_query("SELECT DISTINCT date FROM `work_details` WHERE  employee_id='".$emp_id."' and date between '".$start_date."' and '".$end_date."'");
  
   do
       {
               while($row=mysql_fetch_array($work_res))
                  {
                   while((date("Y-m-d",$test_date)&lt;$row['date'])&amp;&amp;($flag=0))
  
                   {
  
                       if(!(date('N', strtotime(date("Y-m-d", $test_date))) &gt;= 6))
                       {
                           echo  "&lt;tr&gt;&lt;td align=center class=fontclass style=color:FF0000&gt;".date("Y-m-d", $test_date)."&lt;/td&gt;&lt;/tr&gt;";
                             $count_leaves++;
                       }
                          $test_date = $test_date + ($day_incrementer * 60 * 60 * 24);
  
  
                   }
                   $flag=1;
  
  
                   while((date("Y-m-d",$test_date)!=$row['date']))
                      {
                     if(!(date('N', strtotime(date("Y-m-d", $test_date))) &gt;= 6))
                     {
                        echo  "&lt;tr&gt;&lt;td align=center class=fontclass style=color:FF0000&gt;".date("Y-m-d", $test_date)."&lt;/td&gt;&lt;/tr&gt;";
                         $count_leaves++;
                     }
                         $test_date = $test_date + ($day_incrementer * 60 * 60 * 24);
  
  
                      }
                       $test_date = $test_date + ($day_incrementer * 60 * 60 * 24);
  
  
  
                   }
                  if(!(date('N', strtotime(date("Y-m-d", $test_date))) &gt;= 6)&amp;&amp;($test_date &lt;= $end_date))
                      {
                           echo  "&lt;tr&gt;&lt;td align=center class=fontclass style=color:FF0000&gt;".date("Y-m-d", $test_date)."&lt;/td&gt;&lt;/tr&gt;";
                           $count_leaves++;
                           $test_date = $test_date + ($day_incrementer * 60 * 60 * 24);
  
  
                      }
  
  
  }
  while ( $test_date &lt;= $end_date);
  
  return($count_leaves);
   }
  </code></pre>