This topic is locked

Can I use a variable in the SQL query?

4/21/2007 3:21:04 AM
PHPRunner General questions
D
dani author

I'd like to filter the records shown based on some conditions, but those conditions may vary from user to user, so I can't filter by a table element (or everyone would have the same records filtered out).
It's not related to permissions, as each user can decide and change which records to see.
So I was thinking on storing current preferences in a variable, and edit the SQL query to filter based on the value of that variable.
Is this possible?
Thanks
Dani

J
Jane 4/23/2007

Dani,
you can do the following:

  • save current preferences in the $_SESSION variable in the event on the Events tab
  • build your project
  • open generated inlcude/variables.php file and edit query in the $gstrSQL variable.

D
dani author 4/23/2007

Thanks Jane.
I'm trying to avoid editing the built file, because it would have to be redone at every rebuild.
Is there ANY way to introduce a variable element in the query? Other variable besides $_SESSION?
How about if I make an extra column on the table for each user, to store the "visible/hidden" status? In that case the query would have to filter based on the contents of the table, but the name of the column would depend on the user name. Is that possible?
Or even one column to store a string of "users that want to see this record". The query would have to filter a record if username is not inside that field.
Or if I make an extra table with "viewing preferences". Still the query would need to have user or session information into the filter criteria.
Thanks much for your help.
Dani

J
Jane 4/24/2007

Dani,
probably you can do it.

This task can be accomplished using extra table and custom SQL script but you should be familiar with SQL to do that.
Here is some helpful SQL tutorials:

http://webcheatsheet.com/sql/

http://www.w3schools.com/sql/default.asp