Get the length of the variable stored in the database table with codeigniter

0

It turns out that in my database I have a table called votes , in which within the column option I store

a and b

Then I want to get the total amount of 'a' stored in the table as well as the total amount of 'b' stored in the table.

What would be the correct way to do it with CodeIgniter?

    
asked by Hernan Humaña 22.12.2016 в 21:42
source

1 answer

1

You could do it with a where clause in the sql query

For example in your model you could do something like:

function getOpciones($opcion){
  $this->db->select("opcion");
  $this->db->from("votaciones");
  $this->db->where("opcion",$opcion);

  if($query = $this->db->get()){
    return $query->num_rows();
  }else{
    return false;
  }
}

Where the option parameter would be "a" or "b" and you would get the number of rows returned in the query.

    
answered by 22.12.2016 / 21:51
source