0
votes

I need to query the database where the total_pago must equal the valor in the table contas_pagar

class Phpexcel_model extends CI_Model {

function get_users() {
    
    $query = $this->db->get_where("contas_pagar", array('total_pago' == 'valor'));
           
    return $query->result_array();
    
}

Database image

As the image the result should bring only the data that match the query, but it is bringing all the data from the table

4

4 Answers

0
votes

According to the docs (https://codeigniter.com/userguide3/database/query_builder.html#selecting-data) you want the following (note == vs =>):

->get_where('contas_pagar', array('total_pago' => 'valor'))

What you have now is evaluating to

->get_where('contas_pagar', array(false))

because in PHP the string 'total_pago' is not equal to 'valor'.

0
votes

Assuming the total_pago is a numeric field and valor is a variable that contains a number, your get_where statement should be:

->get_where('contas_pagar', array('total_pago' => $valor))
0
votes

you can use this to inspect your query. so that we can see the whole query that is executed by the mysq/sql and so that we can check where the error occur

echo $this->db->last_query()

also alternatively you can use the custom query

$this->db->query('SELECT * FROM contas_pagar WERE total_pago=? ',[$valor])->result_array()
-1
votes
function get_users() {
    
    $query = $this->db->get_where("contas_pagar", array('total_pago' => 'valor'));
           
    return $query->result_array();
    
}