我试图在我的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 :(得分:0)
您使用的是什么SQL引擎?如果它是MySQL,你可以使用:
echo mysql_error();
运行选择后,看看您有什么错误
在生成SELECT语句后也尝试回显它,以确保没有额外的空格等添加到$ fid