怎么做一个' Onclick'将在ID下显示数据的触发器?

时间:2017-03-22 10:17:55

标签: javascript php jquery mysql ajax

我目前有三张桌子。一个是housekeeping_employee,第二个是housekeeping_benefit,第三个是housekeeping_employeebenefits。 housekeeping_Employeebenefits是我的表格,其中为员工分配/插入福利。这是我在下拉列表中显示housekeeping_employee的代码,在复选框中显示housekeeping_benefit,最后是employeebenefits的提交按钮,以便将福利插入到员工中。

<?php
if(!isset($_POST['insert']))
{
    echo "<br>";
    echo "<form method ='POST' action='' >";
        $ctr = 0;
        $employee = mysqli_query($conn, "SELECT * FROM housekeeping_employee") or DIE("Could not Select");
    echo    "<select class='indent' name = 'Employee'>";
    echo    "<option>Select</option>";
    while($listEmployee = mysqli_fetch_array($employee))
    {
        echo "<option value = ".$listEmployee['employeeid'].">".$listEmployee['firstname']."</option>";
    }
    echo    "</select>";
        echo    "<br><br>";
        echo    "<div class='indent'>";
        $benefits = mysqli_query($conn, "SELECT * FROM housekeeping_benefit")or DIE("SELECT Query not working.");   
            if(mysqli_num_rows($benefits))
            {

                while($row = mysqli_fetch_array($benefits))
                {
                    $ctr++;
                    echo "<h6><input type = 'checkbox' name = 'benefits".$ctr."' value ='".$row['benefitid']."' >".$row['benefitname']." </input></h6> <br>";
                    if($ctr == 5){
                    echo"<br>";
                    $ctr=0;
                    }
                }
                    echo "<br><input type='submit' class='btn btn-info' name='insert' value='Submit'/>";                
            }

        echo "<input type='hidden' name='ctr' value='".$ctr."'/>";
        echo "</form>";
} 
                else
            {
                $employeeid = $_POST['Employee'];

                for($a = 1; $a <= $_POST['ctr'] ; $a++)
                {
                    if(isset($_POST['benefits'.$a]))
                    {
                        $benefitid = $_POST['benefits'.$a];
                        //echo "INSERT INTO `housekeeping_employeebenefits`(`employeeid`,`benefitid`) VALUES('$employeeid','$benefitid')";

                        mysqli_query($conn, "INSERT INTO `housekeeping_employeebenefits`(`employeeid`,`benefitid`) VALUES('$employeeid','$benefitid')") or DIE("Insert query is not working");
                        echo "Employee to Benefits successful!";
                    }
                }
            }
?>

我做了一个连接查询,所以我可以看到员工的好处。这是我的查询

SELECT * FROM housekeeping_employee A,housekeeping_benefit B,housekeeping_employeebenefits C where (A.employeeid = A.employeeid and B.benefitid = C.benefitid) and A.employeeid = 2

我的朋友建议我使用我之前从未听过或使用过的onclick,所以我的主要问题与我目前的情况相差甚远,但现在就是这样。因此,根据我的原始代码,我计划删除显示所有福利复选框的代码,而只是替换它,只显示员工拥有的福利复选框。当我从下拉列表中选择/单击员工时,如何执行将在员工下显示福利复选框的触发器?

修改 如果onclick不是我需要的,我需要什么语法/命令?

0 个答案:

没有答案