从数据库中获取数据并在yii中创建列表框 [英] Fetch data from database and create listbox in yii

查看:103
本文介绍了从数据库中获取数据并在yii中创建列表框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表'tbl_department'与2个字段'dpt_id'n'dpt_name'
i想获取所有'dpt_name'作为页面上的列表框输出。

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.

推荐答案

以下样本优秀的Yii文档,我已经制定了tbl_user的用户名。您可以使用在使用yiic创建空应用程序时安装的最小sql脚本 protected / data / schema.mysql.sql 来获取该表。

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)'));
?>

这篇关于从数据库中获取数据并在yii中创建列表框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆