【发布时间】:2011-01-03 07:51:59
【问题描述】:
我正在开发一个蛋糕 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”
我无法解决问题。
请帮帮我
谢谢,
潘卡伊·库拉纳
【问题讨论】:
-
$sort_range 包含的内容,我认为目前它包含 'placement' 它必须包含 'created'
-
嗨,shakti,排序范围包含:Placement.latest desc
-
改成 Placement.created desc
-
现在将 latest 更改为 created 我得到未定义的索引:最新的 [APP\controllers\placements_controller.php,行 2303]。第 2303 行是 $response->rows[$i]['cell'] = array($student, $contactnumber1, $batch,$result['Placement']['latest']);
-
你原来的错误是SQL错误,能不能把debug设置为“2”,检查一下生成的SQL?
标签: mysql cakephp jqgrid mysql-error-1054