obj =& get_instance(); $this->ci =& get_instance(); $this->ci->load->library('encrypt'); } // ////////////////////////////////////////////////////////////////////////// // 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( 'ubica_datos_lugar' ); // 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 id '; // Build up the SQL query string and run the query $sql = 'SELECT * FROM ubica_datos_lugar ' . $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['idlugar'] = $row['idlugar']; $query_results['url_pagina_oficial'] = $row['url_pagina_oficial']; $query_results['generalidades'] = $row['generalidades']; $query_results['historia'] = $row['historia']; $query_results['como_llegar'] = $row['como_llegar']; $query_results['geografia_y_poblacion'] = $row['geografia_y_poblacion']; $results[] = $query_results; } } return $results; } function ubica($id){ return $this->retrieve_by_pkey($id); } // 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 ubica_datos_lugar WHERE id = $idField LIMIT 1"); if ($query->num_rows() > 0) { $row = $query->row_array(); $query_results['id'] = $row['id']; $query_results['idlugar'] = $row['idlugar']; $query_results['url_pagina_oficial'] = $row['url_pagina_oficial']; $query_results['generalidades'] = $row['generalidades']; $query_results['historia'] = $row['historia']; $query_results['como_llegar'] = $row['como_llegar']; $query_results['geografia_y_poblacion'] = $row['geografia_y_poblacion']; $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('ubica_datos_lugar', $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('ubica_datos_lugar', $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_clasificado 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. } ?>