CodeIgniter: Choosing a Data From GET

CodeIgniter Step By Step Tutorial: At previous tutorial, we learn show a data. But we have define ID that we want to show. In this post, we learn how to show a data that ID defined from GET.

For model: Open “books_model.php” within CodeIgniter\system\application\models. Add following function:

<?php
	class Books_model extends Model{
	
	function Books_model(){

	parent::Model();

	}


	function books_get($id){

	$this->load->database();

	$query =$this->db->getwhere('books',array('id'=>$id));
	return $query->row_array();
	}

}
?>


codeigniter model

For Controller: Open “books.php” within CodeIgniter\system\application\controllers. Add following function:

<?php
class Books extends Controller{
	
	function Books(){

	parent::Controller();

	}

		
	function Get($id){
		
	$this->load->model('books_model');

	$data['query']=
	$this->books_model->books_get($id);
	

	$this->load->view('books_view',$data);	
	}



}
?>

codeigniter result

Here is the view code within CodeIgniter\system\application\views.

<b>Book Title :</b><?= $query['title'] ?><br/>
<b>Author Name :</b><?= $query['author_name'] ?>
your code here

Now, test it. Point your browser to http://localhost/CodeIgniter/index.php/Book/Get/1.
codeigniter result putput

 

the coder

One Comment on "CodeIgniter: Choosing a Data From GET"

  1. Tanim says:

    This was very helpful…… Thanx a lot

Got something to say? Go for it!

*

 
More in beginners (1 of 10 articles)