get different tables data in different array index in a single method in a model - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: get different tables data in different array index in a single method in a model (/showthread.php?tid=24108) |
get different tables data in different array index in a single method in a model - El Forum - 10-31-2009 [eluser]ranjitbd[/eluser] Code: // this is a controller name holiday.php get different tables data in different array index in a single method in a model - El Forum - 10-31-2009 [eluser]Krzemo[/eluser] Men... what a mess! I don't get at all what you want to achieve. I guess you should rewrite your question if you want to have answers that make sense... get different tables data in different array index in a single method in a model - El Forum - 10-31-2009 [eluser]ranjitbd[/eluser] [quote author="ranjitbd" date="1256996435"][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']); // here i want to get the array value? which is sent by holiday_model. } // 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(); // why this line not working ? produce the following errors //Fatal error: Call to a member function result_array() on a non-object // so how can i sent $query to controller.... // return $query; // this line does not shows any error.but when i print // from the controller 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 ) ) */ } get different tables data in different array index in a single method in a model - El Forum - 10-31-2009 [eluser]ranjitbd[/eluser] // this is a controller name holiday.php function search_holiday() { $data = array(); $data[‘view_pack’] = $this->holiday->view_package(); echo “”; print_r($data[‘view_pack’]); // here i want to get the array value? which is sent by holiday_model. } // 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(); // why this line not working ? produce the following errors //Fatal error: Call to a member function result_array() on a non-object // so how can i sent $query to controller…. // return $query; // this line does not shows any error.but when i print // from the controller 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 want to see here data from theme_name table and destination table... } get different tables data in different array index in a single method in a model - El Forum - 10-31-2009 [eluser]ranjitbd[/eluser] Code: // this is a controller name holiday.php get different tables data in different array index in a single method in a model - El Forum - 10-31-2009 [eluser]saidai jagan[/eluser] You might use like this $query = 'SELECT * FROM table1'; $result1 = $this->db->query($query); $query = 'SELECT * FROM table2'; $result2 = $this->db->query($query); return (array('result_1' => $result1->result_array(),'result_2' => $result2->result_array())); get different tables data in different array index in a single method in a model - El Forum - 10-31-2009 [eluser]Ben Edmunds[/eluser] Try this model Code: $sql = “select theme, destination from theme_name”; then in your controller Code: $data = array(); That model will select the two fields you need from the table and return them as an array. Then the controller is printing the array. get different tables data in different array index in a single method in a model - El Forum - 10-31-2009 [eluser]Pascal Kriete[/eluser] Hi ranjitbd. I've merged these 3 threads as they all pertain to the same question. Having it in one spot makes it easier on everyone. Please refrain from double posting in the future. Thanks. |