I have a problem in this line, where i manage to get the data in my database but, i have a problem because what i've got is a object. and also i have two questions:
- Displaying the Data from my view, i dont know how to display the object type.
- From question number 1, i want the object type to be viewed by something like
<li>
where i have my code in view below
Here is my code:
From Controller i have this:
public function index() {
$data = $this->Category_model->loadCategories();
if(empty($data)) {
$this->load->view('customers/header');
$this->load->view('customers/welcome');
$this->load->view('customers/footer');
}
else {
$this->load->view('customers/header',$data);
$this->load->view('customers/welcome',$data);
$this->load->view('customers/footer',$data);
var_dump($data);
}
}
and in view now here is my problem, i manage to var_dump
this data and the data is look like this:
array(2) { [0]=> object(stdClass)#21 (2) { ["Category_id"]=> string(1) "1" ["Category_name"]=> string(7) "Gadgets" } [1]=> object(stdClass)#22 (2) { ["Category_id"]=> string(1) "2" ["Category_name"]=> string(5) "Books" } }
so my view is this: how can i determine the size of the object so that i will make the size of the object as how many <a href="#" class="list-group-item">Category 1</a>
i will put.
<div class="list-group">
<?php foreach($data) { ?>
<a href="#" class="list-group-item"><?php $Category_name ?></a>
<?php } ?>
</div>