Welcome Guest, Not a member yet? Register   Sign In
get different tables data in different array index in a single method in a model
#1

[eluser]ranjitbd[/eluser]
Code:
// this is a controller name holiday.php

function search_holiday()
    {
        $data = array();
        $data['view_pack'] = $this->holiday->view_package();
        
        echo "<pre>";
        print_r($data['view_pack']);

        $data['mainContent'] = $this->load->view('holiday/search_result', $data, TRUE);
        $this->load->view('index', $data);
    }


// this is the model name holiday_model.php

function view_package()
    {    

        $sql = "select * from theme_name";
        $query['theme'] = $this->db->query($sql);
        
        $sql2 = "select * from destination";
        $query['destination'] = $this->db->query($sql2);

//        return $query->result_array();// this line produce the following errors
//Fatal error: Call to a member function result_array() on a non-object

        return $query; // this line does not shows any error. but when this $query array goes back
// to controller and print the array through this line print_r($data['view_pack']); it does not print the
// table value.it prints.

/*
    Array
(
    [theme] => CI_DB_mysql_result Object
        (
            [conn_id] => Resource id #36
            [result_id] => Resource id #60
            [result_array] => Array
                (
                )

            [result_object] => Array
                (
                )

            [current_row] => 0
            [num_rows] => 0
        )

    [destination] => CI_DB_mysql_result Object
        (
            [conn_id] => Resource id #36
            [result_id] => Resource id #63
            [result_array] => Array
                (
                )

            [result_object] => Array
                (
                )

            [current_row] => 0
            [num_rows] => 0
        )

)
// i need here the table data. how?

*/

    }


// i want to send two table data to controller via view_package() method in the holiday_model.php
// i cant join two tables....so i have to send indivisually like what my coding shows


//practice 2
// instead of two queries if i set two array in the same model and return the array to the controller
// and print the array through this line print_r($data['view_pack']); in the controller..it shows proper
// value

function view_package()
    {    

        $a['small'] = array(array(1,2,3), array(4,5,6));
        $a['big']  = array(array(7,8,9), array(10,11,12));
        
        return $a;
    }
// it shows
/*
    
Array
(
    [small] => Array
        (
            [0] => Array
                (
                    [0] => 1
                    [1] => 2
                    [2] => 3
                )

            [1] => Array
                (
                    [0] => 4
                    [1] => 5
                    [2] => 6
                )

        )

    [big] => Array
        (
            [0] => Array
                (
                    [0] => 7
                    [1] => 8
                    [2] => 9
                )

            [1] => Array
                (
                    [0] => 10
                    [1] => 11
                    [2] => 12
                )

        )

)

*/


Messages In This Thread
get different tables data in different array index in a single method in a model - by El Forum - 10-31-2009, 02:40 AM



Theme © iAndrew 2016 - Forum software by © MyBB