gpt4 book ai didi

php - 在 JQGrid 中动态形成查询

转载 作者:行者123 更新时间:2023-11-29 00:02:19 25 4
gpt4 key购买 nike

我想从表中动态查询数据并根据登录的用户显示它。我有 2 个文件:一个是 index.php,它捕获用户的管理产品,例如:

$currentUser = CurrentUser::getInstance();
$UserID = $currentUser->getId();

//Get admin products
$que1 = mysql_query("SELECT productid from admin_levels WHERE level>1 AND userid=$UserID ORDER BY productid");
$op1="";

while($row1 = mysql_fetch_row($que1)){
foreach($row1 as $cell1){
$op1.=$cell1.",";
}
}

$temp1=strlen($op1)-1;
$op1=substr($op1,0,$temp1);
//op1 contains admin products for sql command
$_SESSION['w1']=$op1;

op1 字符串包含与此类似的内容:

16,17,20,114,125

现在我想将它添加到我的 jqgrid 查询中:

//Get admin products
$y1=$_SESSION['w1'];
$opt1="WHERE issues.productid in (".$y1.")";

//Create query
$grid->SelectCommand = 'SELECT CONCAT(issues.type,"0",issues.kbid) as KBID,issues.issuesummary as Summary,products.productname as Product,issue_priorities.description as Priority,date_format(issues.createddate, "%d/%m/%Y") as Reported,date_format(issues.lastupdated, "%d/%m/%Y") as Updated,issue_status.statusdescription as Status,issue_resolutions.resdescription as Resolution,users.logon as Assigned FROM issues
INNER JOIN issue_priorities ON issue_priorities.VALUE = issues.PRIORITY - 1
INNER JOIN issue_resolutions ON issue_resolutions.RESID = issues.RESOLUTION
INNER JOIN users ON users.ID = issues.ASSIGNEDUSERID
INNER JOIN products ON products.PRODUCTID = issues.PRODUCTID
INNER JOIN issue_status ON issue_status.STATUSID = issues.STATUS'
.$opt1;

在回显 sql 命令时,我得到了这个:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'issues.productid in (16,17,20,114,125) LIMIT 0, 0' at line 6

如何解决这个问题?

最佳答案

出现语法错误可能是单引号试试

 $grid->SelectCommand = "your query".$opt1;

代替

$grid->SelectCommand = 'your query'.$opt1;

关于php - 在 JQGrid 中动态形成查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29210036/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com