Maru
Maru

Reputation: 53

codeigniter - compare values

I need to compare two values in a table: cliente and nro_cuota, if both exist I don't want to add it.

Here is my code

    $crud = new grocery_CRUD();

    $crud->set_theme('datatables');

    $crud->set_table('cobranzas');

    $crud->set_subject('Cobranzas');

    $crud->set_language('spanish');

    $crud->required_fields(
        'id',
        'cobrador',
        'cliente',
        'nro_cuota'
    );

    $crud->columns(
        'cobrador',
        'cliente',
        'nro_cuota'
    );

    $crud->set_relation('cobrador', 'cobradores', 'apellido_nombre');
    $crud->set_relation('cliente', 'clientes', 'apellido_nombre');          

    $output = $crud->render();          

    $this->load->view('cobranzas/cobranzas_v', $output);

}catch(Exception $e){

    show_error($e->getMessage().' --- '.$e->getTraceAsString());
}

}

and I wrote a model, I`m not sure if this is the right way, but I don't know how I must call it

class Compare_values_model extends CI_Model 
{

    public function compare($id)
    {

    $this->db->select('"SELECT * FROM `cobranzas` WHERE `cliente` = '$cliente' AND `nro_cuota` = '$nro_cuota'"');

    if ($query->num_rows() > 0) {
        return true;
    } else {
        return false;
    } 

    }

}

Hope can help me I couldn't find some examples on internet to learn more, thanks in advance.

Upvotes: 0

Views: 1007

Answers (1)

Kumar V
Kumar V

Reputation: 8830

You said I need to compare two values in a table: cliente and nro_cuota, if both exist I don't want to add it. But you are matching the variables with fields. So just check not equal as below:

$query = $this->db->query("SELECT * FROM `cobranzas` WHERE `cliente` <> '$cliente' AND `nro_cuota` <> '$nro_cuota'");

Note: Remove extra single quote in your query

Upvotes: 0

Related Questions