SQLSTATE [42S22]:找不到列:1054'order子句'中的未知列'1'(SQL:从`item`顺序中选择*由`1` asc限制10偏移量0)

时间:2018-10-06 17:03:34

标签: jquery mysql laravel jqgrid

我想在laravel刀片中添加一个jqgrid;但是,存在一个问题“ SQLSTATE [42S22]:找不到列:1054'order子句'中的未知列'1'(SQL:从item中按1顺序选择* * asc限制10偏移量0 )”。我不知道为什么。

我的代码如下:

1.in Blade:

$(document).ready(function () {
    $("#stock_lost").jqGrid({ 
        url:'{{ URL::route('accountData') }}',
        datatype: "json",
        colNames:['id','type','model', 'price', 'currency','123'], 
        colModel:[ 
        {name:'id',index:'id', width:80,key:true,editable:false,hidden:true}, 
        {name:'type',index:'type', width:80,align:'center',editable: true}, 
        {name:'model',index:'model', width:100,align:'center',editable:true}, 
        {name:'price',index:'price', width:80, align:'center',editable:true}, 
        {name:'currency',index:'currency', width:80, align:'center',editable:true},    
        {name:'storage_location',index:'storage_location', width:80, align:'center',editable:true}
        ],
        //multiselect: true, 
        //caption: "Manipulating Array Data",
        rowNum:10,     
        rowList:[10,20,30,40,50],     
        pager:'#lost_pager',           
        autowidth:true,     
        height: "auto",     
        viewrecords:true,     
        multiselectWidth: 25,    
        sortable:true,     
        sortname:'type',    
        sortorder:'asc',     
        rownumbers:true,  
        scrollOffset:0, 
        cellEdit: false,
    });

   $('#stock_lost').navGrid("#lost_pager",
        // the buttons to appear on the toolbar of the grid
        { edit: true, add: true, del: true, refresh: true, view: false, position: "left", cloneToTop: false },

    );
});

</script>

2.in控制器

 public function accountData(Request $request){
        $page = $request->input('page','1');
        $limit = $request->input('limit','10');
        $sidx = $request->input('sidx','1');
        $sord = $request->input('sord','asc');
        $count = item::count();
    // calculate the total pages for the query 
    if( $count > 0 && $limit > 0) {
        $total_pages = ceil($count/$limit);
    }
    else { 
        $total_pages = 0;
    } 
    if ($page > $total_pages)
        $page=$total_pages;
        $start = $limit*$page - $limit;
    if($start <0) 
        $start = 0; 

    $results = DB::table('item')
                ->orderBy($sidx, $sord)
                ->skip($start)->take($limit)
                ->get();
    $response= new \ stdClass();
    $response->page = $page;
    $response->total = $total_pages;
    $response->records = $count;    
    $i=0;

    foreach ($results as $result) {

        $response->rows[$i]['id']=$i+1;
        $response->rows[$i]['cell']=array($result->id, $result->type,$result->model, $result->price, $result->currency, $result->storage_location);
        $i++;
    }
    return json_encode($response);

}

3.inweb

 Route::get('/lost','StockController@accountData')->name('accountData');

4.in表“ item”的模型

namespace App;

use Illuminate\Database\Eloquent\Model;

class item extends Model
{
    protected $table='item';
    protected $primaryKey='id';
    protected $fillable=[
        "type",
        "model",
        "price",
        "currency",
        "storage_location",
    ];
}

0 个答案:

没有答案