在 Jstree 复选框中调用 ajax 并将选中的数据传递给控制器​​ (Codeigniter)

Call ajax in Jstree checkbox and pass checked data to controller (Codeigniter)

我在 codeigniter 中使用 JStree 复选框,我可以使用以下代码打印他的复选框 jstree。

<script>
 $("#newtree").jstree({
        "checkbox" : {
          "keep_selected_style" : false
            },
           "plugins" : [ "checkbox" ]
             });

</script>

我想做的是检查选中的复选框并相应地更改我在 codeigniter 模型中的 MySql SELECT 语句。

示例:如果我检查男性,我的 sql 语句必须是 Select * from students where gender=Male 否则我的 sql 语句应该是 Select * from students.

此外,如果我选中多个复选框,SQLquery 应该附加选中的结果。 示例:如果我选中 Male 和 Science sql query 应该是: Select * from students where gender=male and subject=science

$sql = "SELECT * FROM `students`";

$addition = [];

if ($gender == 'male')
{
    $addition[] = " WHERE `gender`='male'";
}

if ($subject == 'science')
{
    $addition[] = " WHERE `subject`='science'";
}

/*
 * other conditions if any
 */

if (count($addition))
{
    foreach($addition as $k => $v)
    {
        if ($k < 1)
        {
            $sql .= $v;
        }
        else
        {
            $sql .= " AND" . $v;
        }
    }
}