Как обновить данные таблицы, нажав одну и ту же кнопку? - PullRequest
0 голосов
/ 12 декабря 2018
<script>
    $(document).ready(function(){
        $("#submit").click(function(e){
            e.preventDefault();
            uid = $("input[name='user_id']:checked").map(function() {
                    return this.id;
                }).get().join(",");
            $.ajax({
                type:"POST",
                data:{"uid":uid},
                url:"<?php echo base_url(); ?>hr/shortlist",
                success:function(data){
                    setTimeout(function(){
                        location.reload();
                    }, 1000);
                }
            });
        });
    });
</script>

<table>
    <thead>
        <tr class="info">
            <th>Check</th>
            <th>Recruiter Id</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>
                <input type="checkbox" name="user_id" id="uid1211120937" class="user_id">
            </td>
            <td>20181123091338</td>
        </tr>
        <tr>
            <td>
                <input type="checkbox" name="user_id" id="uid1211092847" class="user_id">
            </td>
            <td>20181123091338</td>
        </tr>       
    </tbody>
</table>
<input type="submit" name="submit" id="submit" value="short"/>

shortlist.php

$uid = explode(",",$this->input->post('uid'));
foreach($uid as $user_id)
{
    $data = array('shortlist'=>'1');
    $this->db->where('uid',$user_id);
    $query = $this->db->update('personal_detail',$data);
}

В этом вопросе у меня несколько флажков.Теперь, что я хочу, если, если я установил флажок «все», то shortlist must be 1 for all будет обновлен, а если я сниму флажок, то uncheck checkbox value will be 0.Итак, как я могу это сделать?Пожалуйста, помогите мне.

Спасибо

1 Ответ

0 голосов
/ 12 декабря 2018

Вам нужно найти все флажки состояния относительно идентификатора пользователя.

$(document).ready(function(){
    $("#submit").click(function(e){
        e.preventDefault();

        var uids = [];

        $("input[name='user_id']").map(function() {
            uids.push({id: this.id, value: this.checked ? 1 : 0});
        });

        $.ajax({
            type:"POST",
            data:{"uid":uids},
            url:"<?php echo base_url(); ?>hr/shortlist",
            success:function(data){
                setTimeout(function(){
                    location.reload();
                }, 1000);
            }
        });
    });
});

Теперь в shortlist.php

$uid = $this->input->post('uid');

foreach($uid as $user)
{
    $data = array('shortlist'=> $user['value']);
    $this->db->where('uid',$user['id']);
    $query = $this->db->update('personal_detail',$data);
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...