Welcome Guest, Not a member yet? Register   Sign In
Accessing data in controller
#1

[eluser]Martin Rusev[/eluser]
Hello everybody,

I am pretty new to php an Codeigniter. Right now i am writing my first real world application. From some time i am facing the following problem

I have this hierarchy: main category -> subcategory -> product

Đ•very page has a breadcrumb - I load all the information and the breadcrumb information at the same time with the following :
Code:
// Loading Main category name from the database
$this->load->model('maincategories');
    $data['main_category'] = $this->maincategories->get_maincategories_id($main_id);
    
//Loading Products        
    $this->load->model('productsmodel');
    $products = $this->productsmodel->get_products($id);
//get_products returns array
Array
(
    [0] => stdClass Object
        (
            [id] => 1
            [subcategory_id] => 2
            [article] => Article 1
            [product_name] => Product Name 1
            [product_thickness] => 12
            [product_lenght] => 180
            [product_weight] => 122
            [product_price] => 230
        )

    [1] => stdClass Object
        (
            [id] => 5
            [subcategory_id] => 2
            [article] => Article 2
            [product_name] => Product Name 2
            [product_thickness] => 23
            [product_lenght] => 23
            [product_weight] => 23
            [product_price] => 23
        )

And finally i want to access subcategory_id from this array and pass it back to my model
for retrieving Subcategory name from another table in the database
Code:
$this->load->model('subcategoriesmodel');
    $subcategory = $this->subcategoriesmodel->get_subcategory_name($subcategory_id);

thanks
#2

[eluser]tonanbarbarian[/eluser]
fail to see what the problem is?

is there an error or something?
#3

[eluser]Martin Rusev[/eluser]
Yes there is Smile

I want to retrieve all the information from the database and then use it and pass only subcategory_id from the retrieved array back to another model that retrieves Subcategory name from another table
From this array - i am trying to take the value of subcategory_id - all this happens in the controller i searched through the forum and don't found any way to take this value
Code:
Array
(
    [0] => stdClass Object
        (
            [id] => 1
            [subcategory_id] => 2
            [article] => Article 1
            [product_name] => Product Name 1
            [product_thickness] => 12
            [product_lenght] => 180
            [product_weight] => 122
            [product_price] => 230
        )

    [1] => stdClass Object
        (
            [id] => 5
            [subcategory_id] => 2
            [article] => Article 2
            [product_name] => Product Name 2
            [product_thickness] => 23
            [product_lenght] => 23
            [product_weight] => 23
            [product_price] => 23
        )
#4

[eluser]tonanbarbarian[/eluser]
This is just basic PHP
Code:
$products[0]->subcategory_id
there are any number of other ways you can do it depending on whether you need the subcategory of the first item or the last or whatever




Theme © iAndrew 2016 - Forum software by © MyBB