使用jquery和ajax删除表行(foreach循环)

时间:2018-10-24 15:39:40

标签: php jquery mysql ajax

我正在尝试基于这样的输入字段的取消选中框删除表行,

input checkbox

这些是输入字段,

Level 1<input value="1" class="checkbox" type="checkbox" name="rubric_chkbox[]" />
Level 2<input value="2" class="checkbox" type="checkbox" name="rubric_chkbox[]" />
Level 3<input value="3" class="checkbox" type="checkbox" name="rubric_chkbox[]" />

我正在使用下一个jquery代码来获取数据,

var uncheked = [];

$("input[name='rubric_chkbox[]']:not(:checked)").each(function()
{
    uncheked.push($(this).val()); 
});

console.log(uncheked);

Console.log返回数组值[“ 3”],它是未选中的复选框值。

这是我在PHP上的foreach循环,

if (isset($_POST['uncheked']) || isset($_POST['user_id']))
{
    $rubric_uncheck_value = $_POST['uncheked'];    
    $IDuser = $_POST['user_id'];

    foreach($rubric_uncheck_value as $rubric_uncheck)
    {
        $sql_check = "SELECT raw_selected_rubric
                      FROM rubric_selected
                      INNER JOIN cmat_composition ON rubric_selected.ID_cmat = cmat_composition.ID_cmat
                      WHERE rubric_selected.ID_users = '$IDuser'
                      AND raw_selected_rubric = '$rubric_uncheck'
                      AND rubric_selected.Saved = '1'";

        $result_check = mysqli_query($conn,$sql_check);

        if (mysqli_num_rows($result_check) > 0)
        {                
            $sql_raw = "DELETE raw_selected_rubric
                        FROM rubric_selected
                        WHERE raw_selected_rubric = '$rubric_uncheck'
                        AND ID_users = ''$IDuser'";

            mysqli_query($conn, $sql_raw);

            $sql_to_validated = "DELETE selected_rubric
                                 FROM validated_score
                                 WHERE selected_rubric = '$rubric_uncheck'
                                 AND ID_users = ''$IDuser'";

            mysqli_query($conn, $sql_to_validated);
        }
    }
}

但是这什么也没做。可能是什么问题?请帮助。谢谢。

0 个答案:

没有答案