obj =& get_instance(); } // ////////////////////////////////////////////////////////////////////////// // Function: findAll() // // Description: Retrieves and returns data listing from the database // // ////////////////////////////////////////////////////////////////////////// function findAll($start = NULL, $count = NULL) { return $this->find(NULL, $start, $count); } // function findById($key_value) { // return $this->find(array('id' => '$key_value')); // } function findByFilter($filter_rules, $start = NULL, $count = NULL) { return $this->find($filter_rules, $start, $count); } function find($filters = NULL, $start = NULL, $count = NULL) { $results = array(); // Load the database library $this->load->database(); // /////////////////////////////////////////////////////////////////////// // Make a note of the current table record count // /////////////////////////////////////////////////////////////////////// $this->table_record_count = $this->db->count_all( 'cla_sub_categoria' ); // Filter could be an array or filter values or an SQL string. $where_clause = ''; if ($filters) { if ( is_string($filters) ) { $where_clause = $filters; } elseif ( is_array($filters) ) { // Build your filter rules if ( count($filters) > 0 ) { foreach ($filters as $field => $value) { $filter_list[] = " $field = '$value' "; } $where_clause = "WHERE " . join(' AND ', $filter_list ); } } } $limit_clause = ''; if ($start) { if ($count) { $limit_clause = " LIMIT $start, $count "; } else { $limit_clause = " LIMIT $start "; } } $order=' order by nombre '; // Build up the SQL query string and run the query $sql = 'SELECT * FROM cla_sub_categoria ' . $where_clause . $order .$limit_clause; $query = $this->db->query($sql); if ($query->num_rows() > 0) { // //////////////////////////////////////////////////////////////////// // NOTE: At this stage you could return the entire result set, like: // NOTE: ...return $query->result_array(); // NOTE: ...The generated code loops through the result set to provide // NOTE: ...the oppurtunity to provide further customisations on the // NOTE: ...code (especially if you are generating in verbose mode). // //////////////////////////////////////////////////////////////////// foreach ($query->result_array() as $row) // Go through the result set { // Build up a list for each column from the database and place it in // ...the result set $query_results['id'] = $row['id']; $query_results['nombre'] = $row['nombre']; $query_results['nombre_en'] = $row['nombre_en']; $query_results['id_cla_categoria'] = $row['id_cla_categoria']; $results[] = $query_results; } } return $results; } // TODO: this won't be possible if there is no primary key for the table. function retrieve_by_pkey($idField) { $results = array(); // Load the db library $this->load->database(); $query = $this->db->query("SELECT * FROM cla_sub_categoria WHERE id = '$idField' LIMIT 1"); if ($query->num_rows() > 0) { $row = $query->row_array(); $query_results['id'] = $row['id']; $query_results['nombre'] = $row['nombre']; $query_results['nombre_en'] = $row['nombre_en']; $query_results['id_cla_categoria'] = $row['id_cla_categoria']; $results = $query_results; } else { $results = false; } return $results; } function add( $data ) { // Load the database library $this->load->database(); // Build up the SQL query string $sql = $this->db->insert_string('cla_sub_categoria', $data); $query = $this->db->query($sql); return $this->db->insert_id(); } function modify($keyvalue, $data) { // Load the database library $this->load->database(); // Build up the SQL query string $where = "id = $keyvalue"; $sql = $this->db->update_string('cla_sub_categoria', $data, $where); $query = $this->db->query($sql); } function delete_by_pkey($idField) { // Load the db library $this->load->database(); // /////////////////////////////////////////////////////////////////////// // TODO: Just to eliminate nasty mishaps, the delete query has been // TODO: ...deliberately disabled. Enable it if you mean to by uncommenting // TODO: ...the query function call below // /////////////////////////////////////////////////////////////////////// // $query = $this->db->query("DELETE FROM cla_sub_categoria WHERE id = '$idField' "); return true; } // Function used to initilialise class variables. // NOTE: Not particularly useful unless you are using model persistence // NOTE: You may want to add default values here. function obtenerTodo(){ $results = array(); $this->load->database(); $sql=" select cat.id as cat_id, cat.nombre as cat_nombre, sub.id as sub_id, sub.nombre as sub_nombre from cla_categoria cat, cla_sub_categoria sub where cat.id=sub.id_cla_categoria order by cat_nombre, sub_nombre"; $query = $this->db->query($sql); if ($query->num_rows() > 0) { foreach ($query->result_array() as $row) { $query_results['cat_id'] = $row['cat_id']; $query_results['cat_nombre'] = $row['cat_nombre']; $query_results['sub_id'] = $row['sub_id']; $query_results['sub_nombre'] = $row['sub_nombre']; $results[] = $query_results; } } return $results; } function obtenerCatVentas(){ $results = array(); $this->load->database(); $sql=" select cat.id as cat_id, cat.nombre as cat_nombre, sub.id as sub_id, sub.nombre as sub_nombre from cla_categoria cat, cla_sub_categoria sub where cat.id=2 and cat.id=sub.id_cla_categoria order by cat_nombre, sub_nombre"; //echo $sql; $query = $this->db->query($sql); if ($query->num_rows() > 0) { foreach ($query->result_array() as $row) { $query_results['cat_id'] = $row['cat_id']; $query_results['cat_nombre'] = $row['cat_nombre']; $query_results['sub_id'] = $row['sub_id']; $query_results['sub_nombre'] = $row['sub_nombre']; $results[] = $query_results; } } return $results; } function obtenerCatArriendos(){ $results = array(); $this->load->database(); $sql=" select cat.id as cat_id, cat.nombre as cat_nombre, sub.id as sub_id, sub.nombre as sub_nombre from cla_categoria cat, cla_sub_categoria sub where cat.id=1 and cat.id=sub.id_cla_categoria order by cat_nombre, sub_nombre"; $query = $this->db->query($sql); if ($query->num_rows() > 0) { foreach ($query->result_array() as $row) { $query_results['cat_id'] = $row['cat_id']; $query_results['cat_nombre'] = $row['cat_nombre']; $query_results['sub_id'] = $row['sub_id']; $query_results['sub_nombre'] = $row['sub_nombre']; $results[] = $query_results; } } return $results; } function obtenerCatVehiculos(){ $results = array(); $this->load->database(); $sql=" select cat.id as cat_id, cat.nombre as cat_nombre, sub.id as sub_id, sub.nombre as sub_nombre from cla_categoria cat, cla_sub_categoria sub where cat.id=3 and cat.id=sub.id_cla_categoria order by cat_nombre, sub_nombre"; $query = $this->db->query($sql); if ($query->num_rows() > 0) { foreach ($query->result_array() as $row) { $query_results['cat_id'] = $row['cat_id']; $query_results['cat_nombre'] = $row['cat_nombre']; $query_results['sub_id'] = $row['sub_id']; $query_results['sub_nombre'] = $row['sub_nombre']; $results[] = $query_results; } } return $results; } function obtenerCatVarios(){ $results = array(); $this->load->database(); $sql=" select cat.id as cat_id, cat.nombre as cat_nombre, sub.id as sub_id, sub.nombre as sub_nombre from cla_categoria cat, cla_sub_categoria sub where cat.id=4 and cat.id=sub.id_cla_categoria order by cat_nombre, sub_nombre"; $query = $this->db->query($sql); if ($query->num_rows() > 0) { foreach ($query->result_array() as $row) { $query_results['cat_id'] = $row['cat_id']; $query_results['cat_nombre'] = $row['cat_nombre']; $query_results['sub_id'] = $row['sub_id']; $query_results['sub_nombre'] = $row['sub_nombre']; $results[] = $query_results; } } return $results; } } ?>