Welcome Guest, Not a member yet? Register   Sign In
Dont repeat myself...? -- Populating dropdown with DB data
#4

[eluser]rvent[/eluser]
Well it works now..
function in controller:
Code:
function listPrio()
    {
        $qpriority = $this->Smtm->getPriority();
        $ddmenu = array();
        
        foreach($qpriority->result_array() as $row)
        {
            $ddmenu[$row['PartPriority]] = $row['PartPriority];
        }
        
        $priority['options'] = $ddmenu;
        $this->load->view('test', $priority);
    }

function in model:
Code:
function getPriority()
    {
        $this->db->select('PartPriority, PartPriorityID');
        $this->db->from('PartPriority);
        
        $priority = $this->db->get();
        return $priority;
    }

view:
Code:
<html>
    <head>
        <title>Test</title>
    </head>
    <body>
        <form>
        <?php echo form_('PartPriority, $options); ?>
        </form>
    </body>
</html>

Now, there are a few of the same kind i will need to do, like partLocation, PartNumber, PartState, PartStatus, etc. Those will only be dropdown since they are static data, but each value represents a different phase during the repair.

How can i avoid to repeat myself on the code...? Since the only thing that will be changing is the table that is being query..?

Basically, i will have a form for a "board" creation, that form will have several fields; the fields mentioned above reside on different tables and are foreign keys on the main table. So i will need to ID and value field of each of those query...

Will i have to repeat myself..? i dont mind repeating myself, but i think it defeats the purpose of the MVC..?

Thanks for any inputs.


Messages In This Thread
Dont repeat myself...? -- Populating dropdown with DB data - by El Forum - 01-08-2008, 04:03 PM



Theme © iAndrew 2016 - Forum software by © MyBB