我正在开发一个蛋糕 php 应用程序。在这个我使用 jqgrid 来显示我的记录。
这是我的 ctp 文件:
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery("#list").jqGrid(
{
url:'<?php if(!empty($this->params["named"]["batch"]))echo $this->Html->url(array("controller" => "placements", "action" => "report17", "ajax" => true,"batch"=>$this->params["named"]["batch"])); else echo $this->Html->url(array("controller" => "placements", "action" => "report17", "ajax" => true)); ?>',
datatype: "json",
mtype: "GET",
colNames:['Student','Phone No.','Batch','Created'],
colModel:[
{name:'studentname',index:'studentname', width:30, search:true},
{name:'contactnumber1',index:'contactnumber1', width:20, search:true},
{name:'batchname',index:'batchname', width:30, search:true},
{name:'latest',index:'latest', width:30, search:true},
],
rowNum:10,
rowList:[10,20,30],
pager: jQuery('#pager'),
sortname: 'latest',
viewrecords: true,
sortorder: "desc",
caption:"Placements",
height:"auto",
autowidth: true,
navigator:true
});
jQuery("#list").navGrid("#pager",{edit:false,add:false,del:false,search:false});
jQuery("#list").jqGrid('filterToolbar');
})
</script>
这是我在控制器中定义的功能
$conditions = array();
if(!empty($this->params['named']['batch']))
array_push(&$conditions, array('Batch.id' => $this->params['named']['batch'] ));
array_push(&$conditions, array('Student.type' => 'student' ));
array_push(&$conditions, array('Student.trainingcompleted' => '1' ));
$result = $this->Placement->find('all', array(
'fields' => array('id','student_id','company_id','branch_id','max(Placement.created) as latest'),
'link' => array(
'Student' => array(
'Batch'
),
'Company'
),
'group'=>'Placement.student_id',
'conditions'=>$conditions,
'order' => $sort_range,
'limit' => $limit_range
));
}
$i = 0;
$response->page = $page;
$response->total = $total_pages;
$response->records = $count;
//pr($result);
foreach($result as $result)
{
$response->rows[$i]['id'] = $result['Placement']['id'];
$student = "<a href='" . APP_URL . "students/view/" . $result['Student']['id'] . "/by:student'>" . $result['Student']['fullname'] . "</a>";
$batch = "<a href='" . APP_URL . "batches/view/" . $result['Batch']['id'] . "'>" . $result['Batch']['name'] . "</a>";
$contactnumber1 =$result['Student']['contactnumber1'];
$response->rows[$i]['cell'] = array($student, $contactnumber1, $batch,$result['Placement']['latest']);
$i++;
}
echo json_encode($response);
在展示位置表中,学生可能有多个条目。
例如
id student_id istillworking created
1 16 no 2010-09-07 10:02:16
2 16 yes 2010-12-30 12:48:44
我想显示每个用户的最新记录。例如,student_id 16 它应该获取在 2010-12-30 12:48:44 创建的记录。
我试图通过上面的代码来实现这一点。但我收到以下错误:
警告(512):SQL 错误: 1054:“订单子句”中的未知列“Placement.latest”
我无法解决这个问题。
请帮助我
谢谢,
潘卡伊·库拉纳