Error in entering data

Asked

Viewed 37 times

0

Good afternoon Guys,

I am using Ajax to send data from my controller to my view and came across the following problem.

I have this query:

public function get()
{

    $sql = $this->db->select('cliente, programa, proj_principal, informacao, states, codigo')
                    ->from('projetos p')
                    ->join('cliente c', 'p.cliente = c.nome')
                    ->where(' states','1')
                    ->order_by('codigo','ASC')
                    ->get();
    return $sql;
}

That takes the data from the project table and only the client code in the client table. However when it goes to my view only the first item appears as active...

follows JS:

for (j = 0; j < cliente.length; j++) {

                $('#table' + data[i].cliente.replace(/\s/g, '')).append('<tbody><tr><td><p contenteditable="true" id="prog' + cliente[j].id + '">' + cliente[j].programa + '</p></td><td><p contenteditable="true" id="proj' + cliente[j].id + '">' + cliente[j].proj_principal + '</p></td><td class="ml-auto text-center"><p contenteditable="true" id="info' + cliente[j].id + '" >' + cliente[j].informacao + '</p></td>' +
                     '<td><select class="form-control userselect " id="atividades' + cliente[j].id + '">' +
                    '<option value="0">Inativo</option>' +
                    '<option value="1">Ativo</option>' +
                    '</select></td>' +
                    '<td class="ml-auto text-right"><buttom class="btn btn-primary mr-2 botao edit" id="' + cliente[j].id + '"><i class="fas fa-save"></i></buttom><buttom class="btn btn-danger botao remove" id="' + cliente[j].id + '"><i class="fas fa-trash-alt"></i></buttom></td></tr></tbody></table>');

               if (cliente[j].states == 0) {
                    $("#atividades" + cliente[j].id).val(0);
                } else {
                    $("#atividades" + cliente[j].id).val(1);
                }
            console.log($("#atividades" + cliente[j].id).val())
}

If I remove the JOIN, it works perfectly... However I need the Client Code.

Someone from a north ?

1 answer

1


You can do it this way, so it will work:

for (j = 0; j < cliente.length; j++) {

    $('#table' + data[i].cliente.replace(/\s/g, '')).append('<tbody><tr><td><p contenteditable="true" id="prog' + cliente[j].id + '">' + cliente[j].programa + '</p></td><td><p contenteditable="true" id="proj' + cliente[j].id + '">' + cliente[j].proj_principal + '</p></td><td class="ml-auto text-center"><p contenteditable="true" id="info' + cliente[j].id + '" >' + cliente[j].informacao + '</p></td>' +
    '<td><select class="form-control userselect " id="atividades' + cliente[j].id + '">' +
    '<option value="0" '+((cliente[j].state == 0) ? ' selected="selected"' : '')+'>Inativo</option>' +
    '<option value="1" '+((cliente[j].state == 1) ? ' selected="selected"' : '')+'>Ativo</option>' +
    '</select></td>' +
    '<td class="ml-auto text-right"><buttom class="btn btn-primary mr-2 botao edit" id="' + cliente[j].id + '"><i class="fas fa-save"></i></buttom><buttom class="btn btn-danger botao remove" id="' + cliente[j].id + '"><i class="fas fa-trash-alt"></i></buttom></td></tr></tbody></table>');

}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.