0

我试图在我的 SELECT 语句中使用一个变量,但我遇到了一些非常奇怪的问题。代码如下。

不工作,没有数据!

代码:

$fid= $_GET['f']; echo $fid;//prints 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' ";

谢谢你!

网格.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;


?>
4

1 回答 1

0

您使用的是什么 SQL 引擎?如果是 MySQL,您可以使用:

    echo mysql_error();

运行选择以查看您遇到的错误后

还尝试在生成 SELECT 语句后对其进行回显,以确保没有将额外的空格等添加到 $fid

于 2012-08-25T03:06:38.793 回答