Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fetch data from database and create listbox in yii [closed]

i have a table 'tbl_department' with 2 fields 'dpt_id' n 'dpt_name' i want to fetch all 'dpt_name' as listbox output on a page.

like image 511
Frank Avatar asked Nov 27 '25 19:11

Frank


1 Answers

following this sample from excellent Yii documentation, i've worked out the username from tbl_user. You can get that table, using the minimal sql script protected/data/schema.mysql.sql that get installed when you create the empty application with yiic.

<?php
    $records = User::model()->findAll();
    $list = CHtml::listData($records, 'id', 'username');
    echo CHtml::dropDownList('names', null, $list, array('empty' => '(Select a name)'));
?>
like image 69
CapelliC Avatar answered Nov 29 '25 18:11

CapelliC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!