I am a newbie to Codeigniter framework, I have created a simple app that will fetch data from database and then display with condition in Views. I'm trying to display specific data from database to my View, So far, I have no luck using the code below.
Model (Datamodel.php)
function getData() {
$this->db->select("name, value");
$this->db->from('settings');
$query = $this->db->get();
return $query->result_array();
}
Controller (maincontroller.php)
function index()
{
$data['metadata'] = $this->Datamodel->getData();
$this->load->view('viewdata', $data);
}
View
<h3>Site Information</h3>
<?php foreach($metadata as $data) {?>
<h4>Site Title: <?php echo $data['site_title']; ?></h4>
<h4>Site Description: <?php echo $data['site_description']; ?></h4>
<h4>Site keyword: <?php echo $data['site_keyword']; ?></h4>
<h4>Site Year: <?php echo $data['site_year']; ?></h4>
<?php }?>
I want to display something like these on browser:
Site Information
Site Title: My first codeigniter app
Site Description: This is sample ci application
Site keyword: simple ci app, first app
Site Year: 2015
{ Any help & suggestion is accepted. thanks! pls see this image [ http://prntscr.com/722hsm ] for my database structure !}