I am new to CodeIgniter and have a problem I have been unable to figure out. Here is my model class (filename = tenant.php):
<!-- language php --> class tenant extends CI_Model { function getTenants() { $this->db->select()->from('hrs_tenants'); $query=$this->db->get(); return $query->result_array(); } } my controller class (filename = tenants.php):
<!-- language php --> class tenants extends CI_Controller { function index() { $this->load->model('tenant'); $data['tenants']= $this->tenant->getTenants(); echo "<pre>"; print_r($data['tenants']); echo "</pre>"; $this->load->view('tenants', $data); } } and finally my view file (tenants.php):
<!-- language php --> <html> <head> <title>Tenants Listing</title> </head> <body> <h1>Tenants Listing</h1> <?php if(!isset($tenants)) { ?> <p>There are no Tenants to List</p> <?php } else { foreach($tenants as $row){?> <h2><a href="<?php base_url()?>tenants/tenant<?php $row['T_ID']?>"><?php $row['T_Name']?></a></h2> <p>Mobile : <?php $row['T_Mobile']?></p> <?php } } ?> </body> </html> Now coming back to the problem - it should display the tenant name and tenant mobile no., but the view doesn't display it. Instead it shows the static HTML view. But some how it do repeat the tags. Here is the html output/ rendered HTML for the view file:
<pre>Array ( [0] => Array ( [T_ID] => 1 [T_Name] => John Doe [T_Mobile] => 030112345678 ) [1] => Array ( [T_ID] => 2 [T_Name] => Haider Hassan [T_Mobile] => 033412345678 ) ) </pre><html> <head> <title>Tenants Listing</title> </head> <body> <h1>Tenants Listing</h1> <h2><a href="tenants/tenant"></a></h2> <p>Mobile : </p> <h2><a href="tenants/tenant"></a></h2> <p>Mobile : </p> </body> </html> My database is connected fine, as I also did an echo directly in the controller file and it is also generated in the HTML file within pre tag.
Did I forgot to add something, why am I running into this issue?
$tenants['T_ID']directly and see if that works.