Welcome Guest, Not a member yet? Register   Sign In
Displaying results from a table
#1

[eluser]mdcode[/eluser]
I find myself in a little bit of trouble here, working through tutorials and things trying to get a list of names to display dependent on which option is seslected on a dropdown list. Here's what I have so far:

CONTROLLER
Code:
function index()
    {
    
            /* grab the division list */
            if ($divisions = $this->main->get_all_divisions())
            $data['divisions'][$value['id']=0] = '';
            {
                foreach ($divisions as $key=>$value)
                $data['divisions'][$value['id']] = $value['name'];
            }
    
        $data['site_title'] = $this->config->item('site_title');
        $data['title'] = "Main Page";
        $this->template->write_view('content', 'default/pages/main_index', $data);
        $this->template->render();
    }
    
    function names()
    {
       /* set the POST variable */
        $division = $this->input->post('division', TRUE);
        
        /* grab the division details */
        $item = $this->main->get_division($division);
        
        /* set the output */
        $output = ($item !== FALSE) ? $item : '';
        
        echo $output;
    }

MODEL
Code:
function get_division($division = '')
        {
            $this->db->select('*');
            $this->db->from('users');
            $this->db->where('division',$division);
            
            $query = $this->db->get();
            
            $row = ($query->num_rows() > 0) ? $query->row() : FALSE;
            
            return $row;
        }
VIEW
Code:
$('#division').change(function(){
            var id = $('#division option:selected').val();
            
            $.ajax({
                type: "POST",
                url: "<?php echo site_url('main/names');?>",
                data: { division: id },
                success: function(data){
                    $('#fcall_names').html('');
                    $('#fcall_names').append(data);
                },
            });
            
            return false;
        });

// some other completely non-relevant code...

    <div id="fcall">
        <span class="fontNormal">For function call testing - listing of names on a division
        &lt;?php
        echo br(2);
        echo form_dropdown('division', $divisions, set_value('division'), 'id="division" style="width:180px"');
        ?&gt;
            <div id="fcall_names">
            </div>
        </span>
    </div>

Attempting this with jQuery and AJAX. I would really appreciate someone telling me what I am missing or doing wrong. Thanks in advance.


Messages In This Thread
Displaying results from a table - by El Forum - 08-09-2009, 08:18 PM



Theme © iAndrew 2016 - Forum software by © MyBB