【发布时间】:2014-01-18 18:34:51
【问题描述】:
我已在我的一种控制器方法中构建了此查询。$students = $this->Student->query("SELECT id,name FROM students WHERE id IN (SELECT student_id FROM groups_students WHERE group_id = '$id') ");
我已经对其进行了测试,并且我知道 SQL 返回了正确的数据。在我看来,它显示为$this->Form->input('Student')
我只是希望它打印出可以选择的可能学生的姓名,这就是我选择姓名和 ID 的原因......但是,在我的多选框中,它同时打印出姓名和学生的 id,以及出于某种原因的“学生”一词。
我希望以这种格式从 SQL 返回数据....
Array
(
//[id] => 'displayValue',
[1] => 'displayValue1',
[2] => 'displayValue2',
[4] => 'displayValue4',
[5] => 'displayValue5',
[6] => 'displayValue6',
[3] => 'displayValue3',
)
这是它从$this->Student->find('list').返回数据的方式
根据 CakePHP 文档,这是当前检索时数据的格式化方式。
array(
(int) 0 => array(
'students' => array(
'id' => '2',
'name' => 'evan teague',
'lesson_cost' => null,
'paid_lessons' => null,
'notes' => '',
'created' => '2013-11-21 13:35:17',
'modified' => '2014-01-13 22:31:14'
)
),
(int) 1 => array(
'students' => array(
'id' => '3',
'name' => 'Andrew',
'lesson_cost' => null,
'paid_lessons' => null,
'notes' => '',
'created' => '2013-11-22 10:08:01',
'modified' => '2014-01-13 22:22:50'
)
),
(int) 2 => array(
'students' => array(
'id' => '5',
'name' => 'evan2',
'lesson_cost' => null,
'paid_lessons' => null,
'notes' => '',
'created' => '2013-11-22 14:17:57',
'modified' => '2013-11-22 14:17:57'
)
)
)
对此的任何帮助将不胜感激。
【问题讨论】: