Selecting Data : 1- $this->db->get(); Runs the selection query and returns the result. Can be used by itself to retrieve all records from a table: $query = $this->db->get('mytable'); // Produces: SELECT * FROM mytable The second and third parameters enable you to set a limit and offset clause: $query = $this->db->get('mytab', 17, 70); // Produces: SELECT * FROM mytable LIMIT 20, 10 (in MySQL. Other databases have slightly different syntax) You'll notice that the above function is assigned to a variable named $query, which can be used to show the results: $query = $this->db->get('mytab'); foreach ($query->result() as $row) { echo $row->title; } Please visit the result functions page for a full discussion regarding result generation. $this->db->get_where(); Identical to the above function except that it permits you to add a "where" clause in the second parameter, instead of using the db->where() function: $query = $this->db->get_where('mytab', array('id' => $id), $limit, $offset); 2- $this->db->select(); Permits you to write the SELECT portion of your query: $this->db->select('title, content, date'); $query = $this->db->get('mytable'); // Produces: SELECT title, content, date FROM mytable Note: If you are selecting all (*) from a table you do not need to use this function. When omitted, CodeIgniter assumes you wish to SELECT * $this->db->select() accepts an optional second parameter. If you set it to FALSE, CodeIgniter will not try to protect your field or table names with backticks. This is useful if you need a compound select statement. $this->db->select('(SELECT SUM(payments.amount) FROM payments WHERE payments.invoice_id=4') AS amount_paid', FALSE); $query = $this->db->get('mytable');
yea i wrote this subject about how can you select data from DB over php CI ... and i will complete my lessons about codeigniter thank you
Actually CodeIgniter is obsolete in our days. PHP 5.4 has many interesting features, use them for easy life. Let see your examples in Laravel 5.* (or 4.* no difference) $items = MyModel::get(); foreach ($items as $item) { echo $item->title; } PHP: Looks the same, but $item is an instance of MyModel class. You can use Accessors to change a field logic or relationships to get a related model ($item->tags for example), or many-many more. Few more examples with Laravel Eloquent ORM: Where condition: $items = MyModel::where('karma', '>=', 100)->orderBy('title', 'DESC')->get(); PHP: Get one item by id or throw an error exception: $model = MyModel::findOrFail($id); PHP: Get a single model with related models: $model = MyModel::with('tags')->orderBy('updated_at', 'DESC')->first(); print_r($model->tags->toArray()); // print tags as an array PHP: Print model as JSON string: echo $model->toJSON(); PHP: Create/update model: $model = MyModel::firstOrNew(['slug' => 'hello']); $model->title = 'A new title'; $model->save(); PHP: The main idea is you are working not with data, but object. You can code your business logic inside a model class and your controllers and templates will be smaller and easier to understand and support.
Yeah, I'm trying to figure out if this thread was a question or a statement; the language used is so vague Christmas only knows what it's actually about... Though it does an EXCELLENT job of proving what pointless bloated rubbish Codeigniter is.