Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Execute SQL on button click

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Post Reply
fpdragon
Posts: 38
Joined: Wed May 29, 2019 2:50 pm

Execute SQL on button click

Unread post 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
fpdragon
Posts: 38
Joined: Wed May 29, 2019 2:50 pm

Re: Execute SQL on button click

Unread post 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 ""
fpdragon
Posts: 38
Joined: Wed May 29, 2019 2:50 pm

Re: Execute SQL on button click

Unread post 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.
fpdragon
Posts: 38
Joined: Wed May 29, 2019 2:50 pm

Re: Execute SQL on button click

Unread post by fpdragon »

Maybe the "Filter" or the "Record ID" fields can be used somehow from the Run object?
Janusz
nuBuilder Team
Posts: 508
Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 10 times
Been thanked: 18 times

Re: Execute SQL on button click

Unread post 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
If you like nuBuilder, please leave a review on SourceForge
fpdragon
Posts: 38
Joined: Wed May 29, 2019 2:50 pm

Re: Execute SQL on button click

Unread post 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.
admin
Site Admin
Posts: 2822
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 29 times

Re: Execute SQL on button click

Unread post by admin »

.
Post Reply