Welcome to the nuBuilder Forums!
Register and log in to access exclusive forums and content available only to registered users.
Register and log in to access exclusive forums and content available only to registered users.
Is it possible to import data into a subform from a file?
-
- nuBuilder Team
- Posts: 4305
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 446 times
- Contact:
Re: Is it possible to import data into a subform from a file
That sounds complex. You probably need good PHP and JavaScript skills.
To add a row:
https://wiki.nubuilder.cloud/ ... t#nuAddRow
To add a row:
https://wiki.nubuilder.cloud/ ... t#nuAddRow
-
- nuBuilder Team
- Posts: 506
- Joined: Fri Dec 28, 2018 1:41 pm
- Location: Krakow, Poland
- Has thanked: 8 times
- Been thanked: 18 times
Re: Is it possible to import data into a subform from a file
Hi,
Using PHP function works very well if you want to update subform. The update is directly on the mysql level.
Starting with JS on the specific form you prepare some data to be sent to PHP.
In the php function you can update whatever table - access any data from other sources, ...
and at the end of the JS just to perform nuGetBreadcrumb();
and everything is refreshed.
and just an example from one of my DB of the PHP function ('INSERT_INTO_CONNECTIONS')
Using PHP function works very well if you want to update subform. The update is directly on the mysql level.
Starting with JS on the specific form you prepare some data to be sent to PHP.
In the php function you can update whatever table - access any data from other sources, ...
and at the end of the JS just to perform nuGetBreadcrumb();
and everything is refreshed.
Code: Select all
....
nuSetProperty('CUR_PART_ID',$('#parts_id').val());
nuSetProperty('INSERT_INTO_RAPORTS', q);
nuSetProperty('QTY_OF_RAPORTS', qx);
nuSetProperty('LIST_OF_RAPORTS', arr_uid);
nuSetProperty('CON_PART_ID', id);
...
nuRunPHPHidden('INSERT_INTO_CONNECTIONS','z');
....
nuGetBreadcrumb();
Code: Select all
$pid=('#CON_PART_ID#');
$rqt=('#QTY_OF_RAPORTS#');
$lista=('#LIST_OF_RAPORTS#');
$cur_id='#CUR_PART_ID#';
$arr_lista = explode(',',$lista);
for ($i = 0; $i <= $rqt; $i++) {
$rap_id=$arr_lista[$i];
$uid=nuID();
$x="INSERT INTO connection (connection_id,con_part,con_rap) VALUES ('$uid','$pid','$rap_id')";
nuRunQuery($x);
}
$q="SELECT sus_name FROM zzzzsys_user WHERE zzzzsys_user_id='#USER_ID#';";
$w = nuRunQuery($q);
$r = db_fetch_object($w)->sus_name;
if ($r=='') $r='admin';
$q="UPDATE parts SET par_updated_by = '$r' WHERE parts_id='$cur_id';";
$w = nuRunQuery($q);
//nuDebug($q);
unset($pid,$rqt,$cur_id,$s,$t,$start,$i,$x,$q,$w,$r,$uid,$rap_id,$arr_lista);
If you like nuBuilder, please leave a review on SourceForge
-
- nuBuilder Team
- Posts: 506
- Joined: Fri Dec 28, 2018 1:41 pm
- Location: Krakow, Poland
- Has thanked: 8 times
- Been thanked: 18 times
Re: Is it possible to import data into a subform from a file
and additionally be carefull with a subform with to many lines
you need to set appropriatelly in the php conf file the max_input_vars
bigger numer of lines slows much the application
max subform lines is probaly 999.
you need to set appropriatelly in the php conf file the max_input_vars
bigger numer of lines slows much the application
max subform lines is probaly 999.
If you like nuBuilder, please leave a review on SourceForge
-
- Posts: 366
- Joined: Sat Apr 11, 2020 12:03 am
- Has thanked: 3 times
- Been thanked: 4 times
- Contact:
Re: Is it possible to import data into a subform from a file
Thank you for the attention. I learned a little php and already got working code using phpExcell. Stumbled on adding lines to a subform. How to add a line to a subform in php? I would be grateful for the help.Janusz wrote:and additionally be carefull with a subform with to many lines
you need to set appropriatelly in the php conf file the max_input_vars
bigger numer of lines slows much the application
max subform lines is probaly 999.
Code: Select all
<!doctype>
<html>
<head>
</head>
<body>
<?php
require_once './Classes/PHPExcel.php';
$tmpfname = '/home/igor/Загрузки/2020_06_08_N_gm.xls';
$excelReader = PHPExcel_IOFactory::createReaderForFile($tmpfname);
$excelObj = $excelReader->load($tmpfname);
$worksheet = $excelObj->getSheet(0);
$lastRow = $worksheet->getHighestRow();
echo '<table border="1">';
for ($row = 13; $row <= $lastRow; $row++) {
if ($worksheet->getCell('E'.$row)->getValue() <>"") {
echo '<tr><td>';
echo $worksheet->getCell('E'.$row)->getValue();
echo '</td><td>';
echo $worksheet->getCell('J'.$row)->getValue();
echo '</td><td>';
echo $worksheet->getCell('S'.$row)->getValue();
echo '</td><tr>';
}
}
echo '</table>';
?>
</body>
</html>
-
- nuBuilder Team
- Posts: 4305
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 446 times
- Contact:
Re: Is it possible to import data into a subform from a file
Then how do you want to run this PHP? On button click in your form?
-
- nuBuilder Team
- Posts: 506
- Joined: Fri Dec 28, 2018 1:41 pm
- Location: Krakow, Poland
- Has thanked: 8 times
- Been thanked: 18 times
Re: Is it possible to import data into a subform from a file
First identify the subform mysql table name.
It is composed typically:
subform_row_uniq_id, mainform_id, ... any data...
where mainform_id defines the link with main form
(so all lines from subform table with mainform_id equal to Primary Key of the main form are displayed on the specific form)
to insert from php you can use ex.:
$x="INSERT INTO connection (connection_id,con_part,con_rap) VALUES ('$uid','$pid','$rap_id')";
nuRunQuery($x);
But first you can try with phpMyAdmin/SQL to insert manually one line to the table to see if the subform is updated.
You can copy/duplicate one existing line updating only subform row unique ID
(it must have new subform row unique ID, the same mainform_id to define the link, and other data can be the same or changed)
After doing that go to nuBuilder, refresh, and the new line will be in the subform.
It is composed typically:
subform_row_uniq_id, mainform_id, ... any data...
where mainform_id defines the link with main form
(so all lines from subform table with mainform_id equal to Primary Key of the main form are displayed on the specific form)
to insert from php you can use ex.:
$x="INSERT INTO connection (connection_id,con_part,con_rap) VALUES ('$uid','$pid','$rap_id')";
nuRunQuery($x);
But first you can try with phpMyAdmin/SQL to insert manually one line to the table to see if the subform is updated.
You can copy/duplicate one existing line updating only subform row unique ID
(it must have new subform row unique ID, the same mainform_id to define the link, and other data can be the same or changed)
After doing that go to nuBuilder, refresh, and the new line will be in the subform.
If you like nuBuilder, please leave a review on SourceForge
-
- nuBuilder Team
- Posts: 506
- Joined: Fri Dec 28, 2018 1:41 pm
- Location: Krakow, Poland
- Has thanked: 8 times
- Been thanked: 18 times
Re: Is it possible to import data into a subform from a file
and it can be run on buton click for example
If you like nuBuilder, please leave a review on SourceForge
-
- Posts: 366
- Joined: Sat Apr 11, 2020 12:03 am
- Has thanked: 3 times
- Been thanked: 4 times
- Contact:
Re: Is it possible to import data into a subform from a file
Yes, I have to run php on the main form with a button and get the field value (tab_data = '2020-06-05 08:00:00') on the main form to replace '-' with '_' and '08: 00: 00 ' To 'D' or '20: 00: 00 'to' N ', then I will add the values from the file to the subform.kev1n wrote:Then how do you want to run this PHP? On button click in your form?
So I present the script.
-
- Posts: 366
- Joined: Sat Apr 11, 2020 12:03 am
- Has thanked: 3 times
- Been thanked: 4 times
- Contact:
Re: Is it possible to import data into a subform from a file
It seems to me that working with a table will become more complicated due to the lack of a "new subform row unique ID" in excell.Janusz wrote:First identify the subform mysql table name.
to insert from php you can use ex.:
$x="INSERT INTO connection (connection_id,con_part,con_rap) VALUES ('$uid','$pid','$rap_id')";
nuRunQuery($x);
-
- nuBuilder Team
- Posts: 506
- Joined: Fri Dec 28, 2018 1:41 pm
- Location: Krakow, Poland
- Has thanked: 8 times
- Been thanked: 18 times
Re: Is it possible to import data into a subform from a file
the current form Primary key can be easilly sent from JS to PHP and used in mysql
so you collect data from excel; adding the current record Primary key, inserting data to table and thats all
and for adding subform unique id use nuID(); (for more records - in the loop - every line - has to have new nuID generated)
so you collect data from excel; adding the current record Primary key, inserting data to table and thats all
Code: Select all
//get id of the current main record (JS)
var id=nuGetProperty('record_id');
// prepare to be available in php (JS)
nuSetProperty('CON_PART_ID', id);
//recover and use in PHP (PHP)
$pid=('#CON_PART_ID#');
$uid=nuID();
$x="INSERT INTO connection (connection_id,con_part,con_rap) VALUES ('$uid','$pid','$rap_id')";
If you like nuBuilder, please leave a review on SourceForge