This topic is locked
[SOLVED]

 help with list page filtering

5/21/2012 9:14:19 PM
PHPRunner General questions
W
wildwally author

I'm trying to create a dynamic list page based on the user viewing. I've tried numerous attempts and angles think I was on the right track, but after hard coding some variables I found I have been wrong all along. So the scenerio works like such.
When the user logs in I want a session variable created based on a select query to the user table. For this example lets say the results from the query were user ID 30 & 32. Now from a custom view list page I want only the records that have an owner ID of 30 & 32 to display. Sounds easy enough, right.
So my thoughts were:

  1. I create the query in after successful log in to look up the user ID's (got thisworking).
  2. I was thinking that implode the array from the results into a string would work and store as a session variable (not sure if this was working or right approach)
  3. I went to the List page: Before SQL query and added $strWhereClause = "OwnerID in ('30','32')"; (this was working) But when I tried to bring the session variable I would only get records with 30 or depending on how I changed the coding records with 32.
    So this tells me that the method I'm using in step 2 is not right. Any insight on how I could get my results from this query to work as a varaible.
    Note a simple implode will not work because the string becomes '30,32' and i'm using a SQL IN operator so they need to be in the form of an integer '30,'32'...this is what I have learned through trial and error.
    Thanks in advance.
    edit
    I was able to get the result to work like I wanted; however, if i log in with an account that does not have any thing return in the query then I get an error. So I still have something wrong, here is what I have.



$str = "SELECT ID from dbo.users where MySupervisor = '".$data["ID"]."'";

$results = db_query($str,$conn);

while($row = db_fetch_array($results))

{

$data3[] = $row['ID'];

}
array($data3);

$_SESSION['DirectReports'] = implode(",",$data3);

$_SESSION['DirectReports'] = str_replace(",","','",$_SESSION['DirectReports']);


I tried including an if($data3) but still getting error for $data3.

Sergey Kornilov admin 5/22/2012

Too many extra steps. Try something like this;

$str = "SELECT ID from dbo.users where MySupervisor = '".$data["ID"]."'";

$results = db_query($str,$conn);

$s="";

while($row = db_fetch_array($results))

{

$s .= "'" . $row['ID'] . "',";

}

$_SESSION['DirectReports'] = substr($s,0,-1);