I would like to dynamically query data from a table and display it based on user logged in. I have 2 files : one is the index.php that catches the user’s admin products like :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
$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;
The op1 stringcontains something similar tothis:
16,17,20,114,125
Nowiwant toadd it inmy jqgrid query:
//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;
On echoing the sql command i get this:
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
How to solve this issue?
This topic was modified 9 years, 5 months ago by helloman2504.
This topic was modified 9 years, 5 months ago by tony. Reason: Put code tag to be read better
Look into the old forum on how to pass a parameters in the grid.
You can start from here
Not that the script is executed in two diffrent ways: first time the script creates the grid and get your initial variables passed to the script.
Second time grid made a ajax call to the same link to obtain a data, but this time your custom params are lost.
Look into the last link that I have post here. It will help you.
Can you please post your code?
Please in the future do this, since we can not determine where the problem is.
I hope you understand – this will save your and our time.