Welcome Guest, Not a member yet? Register   Sign In
[RESOLVED] Another "getting objects into a view" thread!
#1

[eluser]octavianmh[/eluser]
Hey guys, thanks in advance. Smile

So I'm kindof beating my head against a wall on this, and think the answer is probably 2.5 minutes of time for the experts. sooo, here goes.

I have a model, which returns multiple rows of data, like this:

Code:
function getUserServiceInfoByUser($email)
    {
        $sql = "SELECT * FROM service, service_types, users, commands WHERE users.user_email = ? AND service.user_id = users.user_id AND service_types.service_type_id = service.service_type_id AND commands.commands_id = service.commands_id";
        $query = $this->db->query($sql, array($email));
        return $query->result();
    }

Simple enough.

My controller grabs this info:

Code:
function index() {
        $this->load->model('Usermodel','user', TRUE);
        if($this->session->userdata('logged_in')) {
            $data = array('serviceData' => $this->user->getUserServiceInfoByUser($this->session->userdata('user_email')) );
            $this->load->view('view_services', $data);
            
        }
    }

Now above.. I'm not entirely sure if that's the way to properly drop this type of data, essentially a multidimensional array, in to the view...

Then my view, which fails with an error:

Code:
<?php
echo $service_type_name;
?>

I've also tried things like:

Code:
<?php
echo $serviceData['service_type_name'];
?>

To no avail. The data is being retrieved from the model correctly, I just don't know where to go from here to dump it out in my view!

Sigh!
#2

[eluser]The Wizard[/eluser]
just parse the data in the model and return an array of data to the controller like:

Code:
function Order_Info( $order_id, $show_critical = FALSE )
    {

        if ( $show_critical == TRUE )
        {
            $this->db->select('order_id, domain_id, user_id, fee, bank_transaction_id, creditcard_id, status');
        }
        elseif ( $show_critical == FALSE )
        {
            $this->db->select('order_id, domain_id, user_id, fee, status');
        }
        
        $this->db->select("DATE_FORMAT( date, '%d.%m.%Y' ) as date", FALSE );
        $this->db->select("DATE_FORMAT( date, '%H:%i:%s' ) as time", FALSE );
              
        $this->db->from('order_list');
        
        $this->db->where( 'order_id', $order_id );

        $query = $this->db->get();
    
        $row = $query->row_array();
    
        return $row;
    
    }
#3

[eluser]elvix[/eluser]
your model is returning an object: try: echo $serviceData->service_type_name

alternately, you could try changing your model to return the result in array format: $query->result_array();
#4

[eluser]octavianmh[/eluser]
Great, solved using herrkaleun's suggestions.. correct, it's been much easier to deal with as an array than an object, for whatever reason.

Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB