Welcome Guest, Not a member yet? Register   Sign In
Trouble pass array from DB, model to view
#1

[eluser]Dandy_andy[/eluser]
This should be relatively simple, but I'm stuck. I have a DB with a table that has some country geo data organised in two rows:- country id (con_id) and country name (name). I have created a Model to extract the data from the DB and I want to pass it to the controller and then on to my view so that I can populate a dropdown list. But I'm having trouble passing an array.

Here is my data...

MODEL:-
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Geo_options extends CI_Model {

//call geo country options
function call_country() {
  
  $this->db->select('con_id, name');
  $query_con = $this->db->get('geo_countries');
  
  foreach ($query_con->result_array() as $row)
  {
  $row['con_id'];
  $row['name'];
  }
  return $row;  

}

}

?>

PART OF THE CONTROLLER:-

Code:
<?php

class User extends CI_Controller {

function myprofile()

{
  $this->load->model('geo_options');
  $data['country'] = $this->geo_options->call_country();
                $this->load->view('myprofile', $data);

}//function index

}

?>

MY VIEW (written just to test the output at the moment but what I want to do is populate an HTML dropdown list with the relevant options values and names:-
Code:
<?php echo $country; ?>

I know I have done something very wrong with passing the array and I would appreciate some help on this... I'm learning slowly but surely!

Thanks in advance.


Messages In This Thread
Trouble pass array from DB, model to view - by El Forum - 06-07-2012, 12:47 PM
Trouble pass array from DB, model to view - by El Forum - 06-07-2012, 12:56 PM
Trouble pass array from DB, model to view - by El Forum - 06-07-2012, 01:03 PM
Trouble pass array from DB, model to view - by El Forum - 06-07-2012, 04:08 PM
Trouble pass array from DB, model to view - by El Forum - 06-07-2012, 07:03 PM
Trouble pass array from DB, model to view - by El Forum - 06-08-2012, 12:29 AM



Theme © iAndrew 2016 - Forum software by © MyBB