base.php(controller folder) : <?php class base extends CI_Controller { function __construct() /*loading constructor*/ { parent::__construct(); } function you() { $data['name']=$this->name; $data['color']=$this->color; } public function getall() /*loading model*/ { $this->load->model('empl'); $data['query']=$this->empl->employeey(); //loading model function $this->load->view('employee',$data); } public function index() { $pageinfo['title']="this is my title"; $pageinfo['heading']="MY HEADING"; $this->load->view('base_view',$pageinfo); $this->getall(); } } ?>
empl.php(model folder) <?php class empl extends CI_Model { /*function __construct() { parent::__construct(); }*/ function employeey() { $this->load->database(); //$this->db->where('id','3'); //used for where condition $query=$this->db->get('sample'); //used for selecting all the values return $query->result(); } } ?>
employee.php(view folder) <?php foreach($query as $rows) { echo $rows->id; echo $rows->name; //echo $rows->number; echo "<br>"; } ?>
Database use database name sample set fields-> id(int(4)), name(varchar(50)) in attachment does not contain database u want to create it by using previous instructions
No comments:
Post a Comment