Welcome Guest, Not a member yet? Register   Sign In
Dynamic drop down list help

Hey folks,
I'm very new to code igniter, and I'm just working my way through a simple dynamic drop down list, but I can't figure out exactly how to get er to work. I've been all over the forums and I can't seem to find anything that will make this happen.
So I have my controller all set up, connecting to my database and loading my model, but I'm a litle confused on exactly how to pass the data between model and controller and view, also how to generate the list, do I put the for loop in the view, or in the model then pass the data to the controller, etc.
Here's what I have so far, be brutally honest if possible, I apologize if it doesn't make much sense, I've been getting desperate and trying anything really so it's a bit of a mess.

class Country_search extends Controller {

    function Country_search()
    function index()
      $config['hostname'] = "localhost";
    $config['username'] = "root";
    $config['password'] = "";
    $config['database'] = "world";
    $config['dbdriver'] = "mysql";
    $config['dbprefix'] = "";
    $config['pconnect'] = FALSE;
    $config['db_debug'] = TRUE;
    $config['cache_on'] = FALSE;
    $config['cachedir'] = "";
    $config['char_set'] = "utf8";
    $config['dbcollat'] = "utf8_general_ci";

    $data = $this->User_model->get_continents();
    $dropdown = array();
    //foreach ($data)
    //  $dropdown[$data->id] = $data->title;
   // }

        $this->load->view('index', array('dropdown' => $dropdown));

class User_model extends Model {

    function User_model()
    function get_continents()
      $query = $this->db->query('SELECT DISTINCT continent FROM country');
      return $query;

<?php echo doctype('xhtml1-trans') ?>
$link = array(
          'href' => 'CodeIgniter_1.7.2/stuff/assign-2/assets/style.css',
          'rel' => 'stylesheet',
          'type' => 'text/css'
echo link_tag($link);

<title>Country Search</title>

  <div id="wrapper">
    <div id="content">
      &lt;?php echo heading('Search by Continent', 1); ?&gt;
      &lt;?php echo form_open('country_search/country_list'); ?&gt;
            echo form_dropdown('continent', $dropdown);
      &lt;?php echo form_submit('submit', 'Show me the countries!'); ?&gt;  
      &lt;?php echo form_close(); ?&gt;
    <div id="navigation">
      &lt;?php echo ul(anchor('CodeIgniter_1.7.2','Search by Continent')); ?&gt;
    <div id="header">
      <p class="site-name">ISSD 21 CodeIgniter Country Search</p>
      <p class="site-slogan">Ryan Bend</p>
    <div id="footer">

Quote:$data = $this->User_model->get_continents();

I think that you need to call either ->result() if you like objects or ->result_array() if you prefer arrays. Then run a echo
echo "<pre>"; die(var_dump($data));
so that you can see that you actually have something now that you can run a foreach on.

if you run a var_dump of $data now you prolly get something along the lines of mysql result object gibberish

so.... try this:
$data = $this->User_model->get_continents()->result();
echo "<pre>";

Theme © iAndrew 2016 - Forum software by © MyBB