很简单:
find()取表中所有数据中的某条数据。
select()取表中所有数据。
select()
写法
// 地区列表 访问表portal_financial传id为98
$district_list = Db::name("portal_financial")
->where('parent_id=98')
->select();
$this->assign("district_list", $district_list);
dump($district_list);
使用select()
获取表中的数据,打印数据如下(3条数据)
object(think\Collection)#20 (1) {
["items":protected] => array(3) {
[0] => array(6) {
["id"] => int(99)
["name"] => string(9) "东港区"
["parent_id"] => int(98)
["correlation_name"] => string(0) ""
["select_type"] => int(1)
["list_order"] => float(1000)
}
[1] => array(6) {
["id"] => int(100)
["name"] => string(9) "开发区"
["parent_id"] => int(98)
["correlation_name"] => string(0) ""
["select_type"] => int(1)
["list_order"] => float(1000)
}
[2] => array(6) {
["id"] => int(112)
["name"] => string(9) "五莲县"
["parent_id"] => int(98)
["correlation_name"] => string(0) ""
["select_type"] => int(1)
["list_order"] => float(1000)
}
}
}
以上案例,利用select()取第0条数据的写法dump($district_list[0]['name']);
打印结果为string(9) "东港区"
find()
写法
// 地区列表 访问表portal_financial传id为98
$district_list = Db::name("portal_financial")
->where('parent_id=98')
->find();
$this->assign("district_list", $district_list);
dump($district_list);
使用find()
获取表中的数据,打印数据如下(1条数据)
array(6) {
["id"] => int(99)
["name"] => string(9) "东港区"
["parent_id"] => int(98)
["correlation_name"] => string(0) ""
["select_type"] => int(1)
["list_order"] => float(1000)
}
网友评论