2011-05-17 108 views
1

我試圖將搜索工具欄添加到我的jqGrid,但運行到此列未找到錯誤。這裏是php代碼。SQLSTATE [42S22]:未找到列:1054'訂單子句'中的未知列'B.uid'

<?php 
require_once '../jq-config.php'; 
// include the jqGrid Class 
require_once ABSPATH."php/jqGrid.php"; 
// include the driver class 
require_once ABSPATH."php/jqGridPdo.php"; 
// Connection to the server 
$conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD); 
// Tell the db that we use utf-8 
$conn->query("SET NAMES utf8"); 

// Create the jqGrid instance 
$grid = new jqGridRender($conn); 
// Write the SQL Query 
$grid->SelectCommand = "select A.email , 
            A.first_name , 
            A.last_name , 
            A.dob , 
            B.uid , 
            B.profile_name , 
            B.rating , 
            B.status 
          from B join 
           A 
          on 
           B.uid = A.uid"; 
// Set the table to where you add the data 
$grid->table = 'B'; 
$grid->setPrimaryKeyId('uid'); 
// Set output format to json 
$grid->dataType = 'json'; 
// Let the grid create the model 
$grid->setColModel(); 

// Set the url from where we obtain the data 
$grid->setUrl('grid.php'); 
$grid->addCol(array(
    "name"=>"actions", 
    "formatter"=>"actions", 
    "editable"=>false, 
    "sortable"=>false, 
    "resizable"=>true, 
    "fixed"=>false, 
    "width"=>100, 
    "formatoptions"=>array("keys"=>true) 
    ), "first"); 
$grid->setColProperty('uid', array('editable'=>false, 'label'=>"Reader ID", 'search'=>false)); 
$grid->setColProperty('email', array('editable'=>true, 'label'=>"Reader Email")); 
$grid->setColProperty('first_name', array('label'=>"Reader First Name",'search'=>true)); 
$grid->setColProperty('last_name', array('label'=>"Reader Last Name")); 
$grid->setColProperty('profile_name', array('label'=>"Reader Profile Name")); 
$grid->setColProperty('rating', array('label'=>"Reader rating")); 
$grid->setColProperty('dob', 
     array("formatter"=>"date","formatoptions"=>array("srcformat"=>"Y-m-d H:i:s", "newformat"=>"Y-m-d"), "label"=>"Reader DoB")); 
$statuValue = array("approved"=>"Approved", "disabled"=>"Disabled", "created"=>"Created"); 
$grid->setColProperty('status', array('edittype'=>'select', 'label'=>"Reader Status")); 
$grid->setSelect('status', $statuValue, false, true, false, array("approved"=> "Approved")); 
// This command is executed after edit 
$cid = jqGridUtils::GetParam('uid'); 
$firstName = jqGridUtils::GetParam('first_name'); 
$lastName = jqGridUtils::GetParam('last_name'); 
$email = jqGridUtils::GetParam('email'); 
$dateOfBirth = jqGridUtils::GetParam('dob'); 
// This command is executed immediatley after edit occur. 
$grid->setAfterCrudAction('edit', "update A set A.first_name=?, 
                  A.last_name=?, 
                  A.email=?, 
                  A.dob=? 
                  where A.uid=?", 
                  array($firstName,$lastName,$email,$dateOfBirth,$cid)); 

$grid->setGridOptions(array(
    "rowNum"=>100, 
    "rowList"=>array(100,150,200), 
    "sortname"=>"B.uid", 
    "width"=>1200, 
    "height"=>400 
)); 

$grid->toolbarfilter=true; 
$grid->setFilterOptions(array("stringResult"=>true)); 

$grid->setColProperty('first_name',array("searchoptions"=>array("sopt"=>array("cn")))); 

$grid->renderGrid('#grid','#pager',true, null, null, true,true); 
$conn = null; 
?> 

無論何時我搜索某個特定值的列,都會得到SQL錯誤。這裏是螢火蟲的細節:

_search true 
filters {"groupOp":"AND","rules":[{"field":"first_name","op":"cn","data":"Hello"}]} 
nd 1305657475487 
oper grid 
page 1 
rows 100 
sidx B.uid 
sord asc 
+0

爲了得到最好的幫助,你應該直接在這裏發表您的代碼,這樣,而不是在pastebin。許多潛在的回答者將不得不在另一個網站上查看,並可能繼續前進。 – 2011-05-17 20:15:30

+0

完成!感謝您的建議 – 2011-05-17 20:18:53

回答

相關問題