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

dm7nw8vv  于 2021-06-18  发布在  Mysql
关注(0)|答案(0)|浏览(292)

我正试图根据我的输入字段的取消选中复选框来删除表行,如下所示,

这些是输入字段,

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);
        }
    }
}

但这没用。有什么问题吗?请帮帮我。谢谢您。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题