This topic is locked

Conditional SQL statuement

9/26/2006 8:57:53 AM
PHPRunner General questions
M
markdorminy author

I have a database in which there are two fields that identify a support team for each record - a director and an analyst. Each analyst is assigned to a director, but analysts may work for more than one director. It's easy to create a sql statement that will retrieve the records for one or the other, but is it possible to generate a conditional sql statement based on who is doing the asking - a director or an analyst? If so, where does it go?
Thanks!

Sergey Kornilov admin 9/26/2006

It's not clear what you like to do with this query. Could you explain it further?

M
markdorminy author 9/26/2006

Sure. Each record is tagged with two fields - one for a director and one for an analyst. If the director is logged in, I want for them to see their records only. If the analyst is logged in, I want for them to see their records only. This can't be accomplished with a "one-size fits all" sql statement because the "owner" data comes from two different fields. It also can't be accomplished with usergroups. I can generate two different views and set the security to accomplish this, but I was hoping there was a way that I could do it with one conditional sql statement.
what I want is:

if $_SESSION['owner_id'] = $an_analyst_id_type then

$sql = "select from table where analyst_id = $_SESSION['owner_id']"

else

$sql = $sql = "select
from table where director_id = $_SESSION['owner_id']"

J
Jane 9/27/2006

Hi,
you can do it to edit ..._list.php file manually.

Open file, find following code snippet:

if(SecuritySQL("Search"))

$strSQL = AddWhere($strSQL, SecuritySQL("Search"));



and replace it with this one:

if ($_SESSION["OwnerID"] == "analyst")

$strSQL.= " where `TableName`.`analyst_id`='".$_SESSION["OwnerID"]."'"

else

$strSQL.= " where `TableName`.`director_id`='".$_SESSION["OwnerID"]."'"



where analyst is your real value, TableName is your actual table name.

M
markdorminy author 9/27/2006

Is there anything this thing won't do? <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=11382&image=1&table=forumreplies' class='bbc_emoticon' alt=':D' />
Thank you VERY much!