Execute SQL on button click

Questions related to customising nuBuilder Forte with Javascript or PHP.

Execute SQL on button click

Postby fpdragon » Wed Sep 04, 2019 10:13 pm

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
fpdragon
 
Posts: 38
Joined: Wed May 29, 2019 10:20 pm

Re: Execute SQL on button click

Postby fpdragon » Wed Sep 04, 2019 10:33 pm

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 ""
fpdragon
 
Posts: 38
Joined: Wed May 29, 2019 10:20 pm

Re: Execute SQL on button click

Postby fpdragon » Wed Sep 04, 2019 10:36 pm

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.
fpdragon
 
Posts: 38
Joined: Wed May 29, 2019 10:20 pm

Re: Execute SQL on button click

Postby fpdragon » Wed Sep 04, 2019 10:40 pm

Maybe the "Filter" or the "Record ID" fields can be used somehow from the Run object?
fpdragon
 
Posts: 38
Joined: Wed May 29, 2019 10:20 pm

Re: Execute SQL on button click

Postby Janusz » Wed Sep 04, 2019 11:50 pm

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
Janusz
 
Posts: 220
Joined: Fri Dec 28, 2018 10:11 pm
Location: Krakow, Poland

Re: Execute SQL on button click

Postby fpdragon » Thu Sep 05, 2019 4:00 pm

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.
fpdragon
 
Posts: 38
Joined: Wed May 29, 2019 10:20 pm

Re: Execute SQL on button click

Postby admin » Fri Sep 06, 2019 10:17 am

.
admin
Site Admin
 
Posts: 3108
Joined: Mon Jun 15, 2009 9:53 am


Return to Custom Code