2012-08-25 45 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