2012-08-25 48 views
0

我試圖在我的SELECT語句中使用一個變量,但我遇到了一些非常奇怪的問題.code下面。jqgrid php SELECT查詢問題

不工作,沒有數據!

代碼:

$ FID = $ _GET [ 'F']; echo $ fid; //打印3 $ SQL =「SELECT threadid,thumb,title,stage,status,startdate,duedate,forumid FROM thread WHERE forumid ='$ fid'」;

工作正常!

**Code:** 




    $SQL = "SELECT threadid, thumb, title, stage, status, startdate ,duedate, forumid FROM thread WHERE forumid ='3' "; 

謝謝!

grid.php

<?php include ("add/add_config.php");?> 
<?php include ("php/jqAutocomplete.php");?> 
<?php include ("php/jqCalendar.php");?> 
<?php include ("php/jqGrid.php");?> 
<?php 
ini_set("display_errors","1"); 
$fid= $_GET['f']; 

include ("php/jqGridPdo.php"); 

$conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD); 

$conn->query("SET NAMES utf8"); 




// Create the jqGrid instance 
$grid = new jqGridRender($conn); 



echo $fid; 

$grid->SelectCommand ="SELECT threadid, thumb, title, stage, status, startdate ,duedate FROM thread WHERE forumid='3'"; 
//$g="SELECT threadid, thumb, title, stage, status, startdate ,duedate, forumid FROM thread WHERE forumid='$fid'"; 
//echo $g; 
// set the ouput format to json 
$grid->dataType = 'json'; 
$grid->table ="thread"; 
$grid->setPrimaryKeyId("threadid"); 


$grid->setUrl('grid.php'); 
$grid->cacheCount = true; 



$grid->addCol(array(
    "name"=>"actions", 
    "formatter"=>"actions", 
    "editable"=>false, 
    "sortable"=>false, 
    "resizable"=>false, 
    "fixed"=>true, 
    "width"=>60, 
    "formatoptions"=>array("keys"=>true) 
    ), "first"); 

$grid->setGridOptions(array(
    "caption"=>"cdbdev", 
    "rownumbers"=>true, 
    "toppager"=>true, 
    "rowNum"=>10, 
    "sortname"=>"threadid", 
    "hoverrows"=>true, 
    "rowList"=>array(10,20,50), 
    "postData"=>array("grid_recs"=>776),  
    "height"=>"auto", 
    "width"=>"auto" 


    )); 


$grid->addCol(array("name"=>"fileToUpload", "editable"=>true, "edittype"=>"file", "editrules"=>array("edithidden"=>true))); 

$upload = <<<UPLOAD 
function(formid) { 
//These are needed for fileupload plugin 
$(formid).attr("method","POST"); 
$(formid).attr("action",""); 
$(formid).attr("enctype","multipart/form-data"); 

$("<br/><button id='buttonUpload'>Upload</button>").insertAfter("#fileToUpload",formid); 
// bind a event 
$("#buttonUpload",formid).click(function(){ 
    $.ajaxFileUpload({ 
     url:'doajaxfileupload.php', 
     secureuri:false, 
     fileElementId:'fileToUpload', 
     dataType: 'json', 
     success: function (data, status) { 
      console.log(data); 
      if(typeof(data.error) != 'undefined') 
      { 
       if(data.error != '') 
       { 
        alert(data.error); 
       }else{ 
        $("#fileToUpload").val(""); 
        alert(data.msg); 
       } 
      } 
     }, 
     error: function (data, status, e) 
     { 
      alert(e); 
     } 
    }); 
    return false; 
}); 
} 
UPLOAD; 

$grid->setJSCode($upload); 


$image = <<<CUSTOM 
function formatImage(cellValue, options, rowObject) { 
    var imageHtml = "<img src='images/" + cellValue + "' originalValue='" + cellValue + "' />"; 
return imageHtml; 
} 
function unformatImage(cellValue, options, cellObject) { 
    return $(cellObject.html()).attr("originalValue"); 
} 
function formatRating(cellValue, options, rowObject) { 
    var color = (parseInt(cellValue) > 0) ? "green" : "red"; 
    var cellHtml = "<span style='color:" + color + "' originalValue='" + 
        cellValue + "'>" + cellValue + "</span>"; 
    return cellHtml; 
} 
function unformatRating(cellValue, options, cellObject) { 
    return $(cellObject.html()).attr("originalValue"); 
} 
CUSTOM; 
$grid->setJSCode($image); 



$grid->setSelect('stage', "SELECT id, name FROM selection where statid=1"); 
$grid->setSelect('status', "SELECT id,name FROM selection where statid=2 "); 



$grid->setColProperty("threadid", array("width"=>80 , "align"=>center)); 
$grid->setColProperty("stage", array("width"=>120 , "align"=>center)); 
$grid->setColProperty("forumid", array("width"=>0 ,)); 
$grid->setColProperty("status", array("width"=>120 , "align"=>center)); 


$grid->setColProperty("title", array("width"=>280, "align"=>center ,"formatter"=>"showlink","formatoptions"=>array("baseLinkUrl"=>"showthread.php", "target"=>"_blank", "idName"=>"t"))); 

$grid->setColProperty("startdate", array("width"=>130,"align"=>center, 
    "formatter"=>"date", 
    "formatoptions"=>array("srcformat"=>"Y-m-d H:i:s","newformat"=>"m/d/Y") 
    ) 
); 

$grid->setColProperty("duedate", array("width"=>130,"align"=>center, 
    "formatter"=>"date", 
    "formatoptions"=>array("srcformat"=>"Y-m-d H:i:s","newformat"=>"m/d/Y") 
    ) 
); 
$grid->setColProperty("CustomerID", array("editrules"=>array("required"=>true))); 
$grid->setAutocomplete("CustomerID",false,"SELECT CustomerID, CompanyName FROM customers WHERE CompanyName LIKE ? ORDER BY CompanyName",null,true,true); 

$grid->setUserTime("m/d/Y"); 
$grid->setUserDate("m/d/Y"); 
$grid->setDatepicker("startdate",array("buttonOnly"=>false)); 
$grid->datearray = array('startdate'); 

$grid->setUserTime("m/d/Y"); 
$grid->setUserDate("m/d/Y"); 
$grid->setDatepicker("duedate",array("buttonOnly"=>false)); 
$grid->datearray = array('duedate'); 


$grid->navigator = true; 


$grid->setNavOptions('navigator', array("cloneToTop"=>true,"excel"=>true,"add"=>false,"edit"=>false,"del"=>false,"view"=>false)); 

$grid->exportfile = 'Report.xls'; 


$grid->setNavOptions('navigator', array("cloneToTop"=>true,"pdf"=>true,"add"=>false,"edit"=>false,"del"=>false,"view"=>false)); 


$grid->inlineNav = true; 
$grid->setNavEvent('edit', 'onInitializeForm', $upload); 



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


?> 

回答

0

什麼SQL引擎您使用的?如果它是MySQL中,你可以使用:

echo mysql_error(); 

運行後的選擇,看你有

也嘗試呼應的SELECT語句有什麼錯誤發生之後,以確保沒有額外的空格等被添加到$ fid

+0

之後,我只是echo $ SQL,它會打印出「SELECT threadid,thumb,title,stage,status,startdate,duedate,forumid FROM thread WHERE forumid ='3'」,但沒有mysql的日期 – xlomy

+0

那麼兩個SQL命令是相同的,所以它導致人們認爲代碼中的其他地方存在一些差異?您是否使用兩個單獨的文件進行比較?如果是這樣,將從$ _GET獲取數據的文件中的變量聲明覆制到正在使用硬編碼值的文件中,並查看是否有效? – LairdPleng

+0

非常感謝!我正在使用一個文件進行比較,並在一個文件上進行調試。 – xlomy