This topic is locked
[SOLVED]

AddWhere() Function in After table initialized Event with an SQL View

8/29/2024 6:46:37 AM
PHPRunner General questions
P
Pietro Arcadio author

Hi, I have this problem.
in my application, in the after successful login event I set a session variable like this

$_SESSION["ufficioScientifica"] = $data["ufficio_Scientifica_FK"];

When I use this variable in the After table initialized event of a table used the following code everything works, this is the code i use

$groups = Security::getUserGroups();
if($groups["admins"]) {
NULL;
} else {
$query->addWhere("tbl_fascicoli.ufficio_Scientifica_FK='" . $_SESSION["ufficioScientifica"] . "'");
}

However, when I use the same code in the same event of a sql view

img alt

my application does not work, this message immediately appears
Fatal error: Uncaught Error: Call to a member function addWhere() on null in V:\AFFAR etc.etc etc.

How can I use AddWhere() function in a sql view?

Thank you all and sorry for my English, I am writing from Italy

Sergey Kornilov 8/29/2024

Where in the manual did you find addWhere() function?

P
Pietro Arcadio author 8/29/2024
Sergey Kornilov 8/29/2024

Correct. Do you see which event you need to use this function in?

img alt

P
Pietro Arcadio author 8/29/2024

Yes sure, the same code in a normal table works fine. In sql view no. Tomorrow i'll can post other screenshot

Sergey Kornilov 8/29/2024

Got it, I thought you were adding this code to After Successful login event.

This addWhere() function doesn't make much sense in SQL Views where you can have just any kind of SQL query like a stored procedure call. It only makes sense when you use a regular table.

What you can try though is SQL variables:
https://xlinesoft.com/phprunner/docs/sql_variables.htm

P
Pietro Arcadio author 9/24/2024

Hi, sorry for the late reply. I solved it as you told me with sql variables. I created a session variable at login and put it in the WHERE clause in the source page

SELECT
...
FROM
`vw_richieste_completo`
WHERE `ufficio_scientifica` LIKE '%:session.query%'

Thanks for the help