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条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀