how to do dynamic drop down menu.

24 views
Skip to first unread message

Bhavani Dasari

unread,
Oct 16, 2014, 9:03:46 AM10/16/14
to codei...@googlegroups.com
Hi,
I'm new to Codeigniter framework and I created a basic drop down menu but i need dyanamic drop down menu using xampp server in php .

Please guide me


Thanks
bhavani.



Damir Sović

unread,
Nov 5, 2014, 7:06:55 PM11/5/14
to codei...@googlegroups.com
Actually, it is not that hard.
1. In database create a table, say, "Items" with fields "code" as varchar(8) and "name" as varchar(45). Fill some data in it.
2. In Model (let's call it "Mydb_model"):
function getItems(){
    $this->db->select('name')
    $res = $this->db->get('items');
    return $res->row_array();
}
3. In Controllers, in function where You want to pass the items:
    $this->load->model('Mydb_model');
    $data["items"] = $this->Mydb_model->getItems();
    ...
    $this->load->view("myPageWhereIsDropdown", $data);
4. In View create page "myPageWhereIsDropdown.php" with code:
    echo form_dropdown('items', $items);

or, using foreach:
4. <select name="items">
<?php foreach($items as $item): ?>
<option name="<?php echo item['code']; ?>"><?php echo item['name'];</option>
<?php endforeach; ?>
(in this case, remove "select" line from Model
Reply all
Reply to author
Forward
0 new messages