1

私はケーキ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' in 'order clause'

私は問題を整理することができません。

これについて私を助けてください

ありがとう、

パンカジ クラナ

4

1 に答える 1

0

「placements」テーブルに「latest」列がないか、$result 変数でそれを渡していません。おそらく、検索ステートメントで列を指定し、「最新」を含めていません。

debug($result); を入れてみてください。ループ内。これにより、渡されたデータが表示されます。

ちなみに、それは良い考えではありません

foreach($result as $result)
{
    ...
}

...文法的に正しくないだけでなく、後で予期しない動作につながる可能性があります。結果を $results (複数形) として渡して実行することをお勧めします。

foreach($results as $result)
{
    ...
}
于 2011-01-03T17:44:26.083 に答える