Page 1 of 1

Execute SQL on button click

Posted: Wed Sep 04, 2019 2:43 pm
by fpdragon
Hello,

I'm fighting with a pretty easy task.

In the edit screen of an item, I want to add a button that does some SQL stuff. (duplaction of the current item + some modifications...) I already have working SQL code.
First I thought: easy. I just have to add an Object and configure it as "Run" button and select a previously added SQL. But it is not possible to select any SQL from a run button.
Then I tried to add a PHP Procedure and used the "nuRunQuery" function to execute every SQL line step by step. But also here I can't select the procedure from the "Run" reference selector.

I hope somebody can help.

BR

Re: Execute SQL on button click

Posted: Wed Sep 04, 2019 3:03 pm
by fpdragon
Seems that I found out why the new php procedure was not shown in the selector.

zzzzsys_php.sph_run must not be NULL but ""
and
zzzzsys_php.sph_system must not be NULL but ""

Re: Execute SQL on button click

Posted: Wed Sep 04, 2019 3:06 pm
by fpdragon
Now I have the next problem that I need to get the id of the current element and use it in the SQL.

First I thought of something like this:

Code: Select all

nuRunQuery("CREATE TEMPORARY TABLE `_copy_table_temp` SELECT * FROM `dl_projects` WHERE `dl_projects_id` = '".nuLookupRecord()->dl_projects_id."';");
but it seems that it is not working.

Re: Execute SQL on button click

Posted: Wed Sep 04, 2019 3:10 pm
by fpdragon
Maybe the "Filter" or the "Record ID" fields can be used somehow from the Run object?

Re: Execute SQL on button click

Posted: Wed Sep 04, 2019 4:20 pm
by Janusz
If you want to read the code from the Lookup object on the current form just use in the php:

Code: Select all

$x=('#ID_of_the_object#');
and

Code: Select all

.... WHERE par_number='$x';";  //for string
or
.... WHERE con_part=$x;";     //for int

Re: Execute SQL on button click

Posted: Thu Sep 05, 2019 8:30 am
by fpdragon
Janusz wrote:If you want to read the code from the Lookup object on the current form just use in the php:

Code: Select all

$x=('#ID_of_the_object#');
and

Code: Select all

.... WHERE par_number='$x';";  //for string
or
.... WHERE con_part=$x;";     //for int
Thank you very much.

It works.

Re: Execute SQL on button click

Posted: Fri Sep 06, 2019 2:47 am
by admin
.