dongqie4233 2015-11-03 06:21
浏览 145
已采纳

Mysql查询按月存储员工出勤率

How do I insert all employee attendance(Monthly once) in mysql database Here is my db tables

att_employee_id | att_year | att_month | att_present_days | att_absent_days |   att_workingdays

Date.prototype.daysInThisMonthOfThisYear=function() {
  return new Date(this.getFullYear(),this.getMonth()+1,0).getDate();
}
var days_inmonth = new Date().daysInThisMonthOfThisYear();

$(document).ready(function() {
    $( ".absent_days" ).keyup(function() {
         var days = $(this).val();
         $(this).closest("tr").find(".present_days" ).val( days_inmonth - days );   
        })  
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<form name="emp_att" action="" method="post">
  <table>
    <thead>
      <tr>
        <th class="head0" style="width:5%">S.No</th>
        <th class="head1" style="width:15%">Employee ID</th>
        <th class="head0 no-sort" style="width:15%">No.of days present</th>
        <th class="head1 no-sort" style="width:15%">No.of days absent</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>1</td>
        <td>ETO0001</td>
        <td><input type="text" class="present_days" name="present_days" value=""></td>
        <td><input type="number" name="absent_days" class="absent_days" min="0" max="<?php echo date('t'); ?>" onChange="absentdays()" style="width:100%"></td>
      </tr>
      <tr>
        <td>2</td>
        <td>ETO0002</td>
        <td><input type="text" class="present_days" name="present_days" value=""></td>
        <td><input type="number" name="absent_days" class="absent_days" min="0" max="<?php echo date('t'); ?>" onChange="absentdays()" style="width:100%"></td>
      </tr>
      <tr>
        <td>3</td>
        <td>ETO0003</td>
        <td><input type="text" class="present_days" name="present_days" value=""></td>
        <td><input type="number" name="absent_days" class="absent_days" min="0" max="<?php echo date('t'); ?>" onChange="absentdays()" style="width:100%"></td>
      </tr>
      <tr>
        <td>4</td>
        <td>ETO0004</td>
        <td><input type="text" class="present_days" name="present_days" value="" readonly></td>
        <td><input type="number" name="absent_days" class="absent_days" min="0" max="<?php echo date('t'); ?>" onChange="absentdays()" style="width:100%"></td>
      </tr>
    </tbody>
  </table>
  <input type="submit" name="submit" value="Submit">
</form>

Here is my query to get all the employees

   <form name="emp_att" action="" method="post">
   <table>
   <thead>
   <tr>
    <th class="head0" style="width:5%">S.No</th>
    <th class="head1" style="width:15%">Employee ID</th>
    <th class="head0 no-sort" style="width:15%">No.of days present</th>
    <th class="head1 no-sort" style="width:15%">No.of days absent</th>
  </tr>
  </thead>
  <tbody>
    <?php
        $allemp= mysqli_query($con,"select * from t_emp e");
          $all_emp = mysqli_num_rows($allemp);

        if ($all_emp > 0)
        {
         $i=1;
            while($all_emp = mysqli_fetch_assoc($allemp))
          {
                 echo "<tr>";
                 echo "<td>".$i."<input type='hidden' name='serialno' value='".$i++."'></td>
                 <td> ".$all_emp["emp_id"]."</td>
                <td><input type='text' class='present_days' name='present_days' value=''></td>";
             echo "<td><input type='number' name='absent_days' class='absent_days' min='0' max= date('t') onChange='absentdays()' style='width:100%'></a></td>"; 
            echo "</tr>";
                 } 
          } 
        else 
        {
            echo "0 Results";
        }
        ?>
      </tbody>
      </table>
      <input type="submit" name="submit" value="Submit">
      </form>

Here I am getting all the n number of employees in the above form. when entered all employees "No.of days absent" and then hit on submit I am able to send only last record to the database. Can any one help me to send all the employees attendance to database Here is my form submission query

<?php
if(isset($_POST['submit']))
{ 
 $serialno=$_post['serialno'];
 $employee_id=$_post['emp_id'];
 $att_year = date('Y'); 
 $att_month = date('m'); 
 for($i=1; $i<= $serialno;$i++)
 {
  $present_days=$_POST['present_days'];
  $absent_days=$_POST['absent_days'];
  }
  $query=mysqli_query($con,"INSERT INTO t_emp_attendance(att_employee_id,att_year,att_month,att_present_days,att_absent_days)values('$employee_id','$att_year','$att_month','$present_days','$absent_days')");
  }
 ?>

any suggestions will be appreciated, I need to store all the employees attendance to database

</div>
  • 写回答

2条回答 默认 最新

  • dsz1966 2015-11-03 06:26
    关注

    Check you spelling for INSERT. And also you have missed to pass the connection object for inserting

    First parameter should be the connection object in mysqli_*

    mysqli_query(connectionObject,your Query);
    
    $query=mysqli_query("INSERT INTO t_emp_attendance(att_employee_id,att_year,att_month,att_present_days,att_absent_days)values('$employee_id','$att_year','$att_month','$present_days','$absent_days')");
    
    
    for($i=1; $i<= $serialno;$i++)
    {
       $present_days=$_POST['present_days'][$i];
       $absent_days=$_POST['absent_days'][$i];
       $query=mysqli_query($con,"INSERT INTO t_emp_attendance(att_employee_id,att_year,att_month,att_present_days,att_absent_days)values('$employee_id','$att_year','$att_month','$present_days','$absent_days')");
    }      
    

    Your query should be inside the loop. And as suggested by parag, make text field names as arrays [] Soomething like this,

    <input type="text" class="present_days" name="present_days[]" value="">
                                                              ^ ^
    

    You shud do for all the text boxes.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题
  • ¥15 使用Java milo连接Kepserver服务端报错?
  • ¥15 用ADS设计一款的射频功率放大器
  • ¥15 怎么求交点连线的理论解?
  • ¥20 软件开发方法学习来了
  • ¥15 微信小程序商城如何实现多商户收款 平台分润抽成