How to update one table using two nurunquery before save

Questions related to using nuBuilder Forte.

Re: How to update one table using two nurunquery before save

Postby kev1n » Mon Apr 22, 2019 10:24 pm

I added a nuDebug($y); to inspect the value of the variable $y. It resolves to
UPDATE kode_barang SET stock_item_kode_barang = '334.0000' WHERE kodebarangid = '5cb81f9800d5f09'

Basically it's trying to set stock_item_kode_barang = '334.0000' (decimal value) but stock_item_kode_barang is of type int(11).

Code: Select all
// Gw coding udah sangat cape, tolong hargai hasil kerja orang
// Hakcipta dan dirancang oleh Yusa Dibrata

$y   = "SELECT * FROM raw_material";
$a   = nuRunQuery($y);

while($u = db_fetch_object($a)){
   
   $y   = "UPDATE kode_barang SET stock_item_kode_barang = '$u->sisa_raw_material' WHERE kode_barang_id = '$u->item_raw_material' ";
   nuDebug($y);
   nuRunQuery($y);
   
}
kev1n
 
Posts: 236
Joined: Mon Oct 15, 2018 2:13 am

Re: How to update one table using two nurunquery before save

Postby yusa82 » Tue Apr 23, 2019 11:00 am

kev1n wrote:I added a nuDebug($y); to inspect the value of the variable $y. It resolves to
UPDATE kode_barang SET stock_item_kode_barang = '334.0000' WHERE kodebarangid = '5cb81f9800d5f09'

Basically it's trying to set stock_item_kode_barang = '334.0000' (decimal value) but stock_item_kode_barang is of type int(11).

Code: Select all
// Gw coding udah sangat cape, tolong hargai hasil kerja orang
// Hakcipta dan dirancang oleh Yusa Dibrata

$y   = "SELECT * FROM raw_material";
$a   = nuRunQuery($y);

while($u = db_fetch_object($a)){
   
   $y   = "UPDATE kode_barang SET stock_item_kode_barang = '$u->sisa_raw_material' WHERE kode_barang_id = '$u->item_raw_material' ";
   nuDebug($y);
   nuRunQuery($y);
   
}


I already change all the counting form into decimal sir, and still not working sir.
yusa82
 
Posts: 19
Joined: Tue Oct 02, 2018 12:59 pm

Re: How to update one table using two nurunquery before save

Postby kev1n » Tue Apr 23, 2019 2:48 pm

Can you upload your db dump again?
kev1n
 
Posts: 236
Joined: Mon Oct 15, 2018 2:13 am

Re: How to update one table using two nurunquery before save

Postby yusa82 » Thu May 02, 2019 12:04 am

kev1n wrote:Can you upload your db dump again?

Here is the SQL file sir
Attachments
oci.zip
SQL DATA
(130.49 KiB) Downloaded 11 times
yusa82
 
Posts: 19
Joined: Tue Oct 02, 2018 12:59 pm

Re: How to update one table using two nurunquery before save

Postby Janusz » Thu May 02, 2019 5:40 am

Hi,
I modified the code as following and looks that it changes values form both querries.

Code: Select all
// Gw coding udah sangat cape, tolong hargai hasil kerja orang
// Hakcipta dan dirancang oleh Yusa Dibrata

$a = "SELECT item_raw_material, sisa_raw_material FROM raw_material";
$z = nuRunQuery($a);
while($c = db_fetch_object($z)){
$x1=$c->sisa_raw_material;
$x2=$c->item_raw_material;
//nuDebug($x1);
//nuDebug($x2);
$d = "UPDATE kode_barang SET stock_item_kode_barang =". $x1." WHERE kode_barang_id ='". $x2."';";
//nuDebug($d);
nuRunQuery($d);
}

$s = "SELECT * FROM produksi";
$t = nuRunQuery($s);
while($r = db_fetch_object($t)){
$x1=$r->total_stock_produksi;
$x2=$r->barang_yang_di_produksi;
//nuDebug($x1);
//nuDebug($x2);
$s = "UPDATE kode_barang SET stock_item_kode_barang =". $x1." WHERE kodebarangid ='". $x2."';";
//nuDebug($s);
nuRunQuery($s);
}
Janusz
 
Posts: 217
Joined: Fri Dec 28, 2018 10:11 pm
Location: Krakow, Poland

Re: How to update one table using two nurunquery before save

Postby Janusz » Thu May 02, 2019 7:38 am

Additionally please verify consistency of other data. When you generate queries you have the following lines generated from your example PIERCHING 3KG.
Please note that lines 3 and 4 are refering twice to the same id but with 2 different values.
ID 5cb8209bb9ad7a0 (line 6) is not existing in the kode_barang table.

1 [0] : UPDATE kode_barang SET stock_item_kode_barang =0.0000 WHERE kode_barang_id ='5cb81dd2dcfc5f7';
2 [0] : UPDATE kode_barang SET stock_item_kode_barang =156.0000 WHERE kode_barang_id ='5cb81f9802c463b';
3 [0] : UPDATE kode_barang SET stock_item_kode_barang =1894.0000 WHERE kode_barang_id ='5cb8193855ff424';
4 [0] : UPDATE kode_barang SET stock_item_kode_barang =3612.0000 WHERE kode_barang_id ='5cb8193855ff424';
5 [0] : UPDATE kode_barang SET stock_item_kode_barang =1062.0000 WHERE kodebarangid ='5cb81dd2db8f2af';
6 [0] : UPDATE kode_barang SET stock_item_kode_barang =128.0000 WHERE kodebarangid ='5cb8209bb9ad7a0';
7 [0] : UPDATE kode_barang SET stock_item_kode_barang =334.0000 WHERE kodebarangid ='5cb81dd2db8f2af';
8 [0] : UPDATE kode_barang SET stock_item_kode_barang =334.0000 WHERE kodebarangid ='5cb81f9800d5f09';
Janusz
 
Posts: 217
Joined: Fri Dec 28, 2018 10:11 pm
Location: Krakow, Poland

Re: How to update one table using two nurunquery before save

Postby admin » Sat May 04, 2019 7:14 am

Guys,

I think the problem is that this PHP code should be in After Save not Before Save.

Steven
admin
Site Admin
 
Posts: 3106
Joined: Mon Jun 15, 2009 9:53 am

Re: How to update one table using two nurunquery before save

Postby yusa82 » Sat May 04, 2019 11:13 am

Janusz wrote:Additionally please verify consistency of other data. When you generate queries you have the following lines generated from your example PIERCHING 3KG.
Please note that lines 3 and 4 are refering twice to the same id but with 2 different values.
ID 5cb8209bb9ad7a0 (line 6) is not existing in the kode_barang table.

1 [0] : UPDATE kode_barang SET stock_item_kode_barang =0.0000 WHERE kode_barang_id ='5cb81dd2dcfc5f7';
2 [0] : UPDATE kode_barang SET stock_item_kode_barang =156.0000 WHERE kode_barang_id ='5cb81f9802c463b';
3 [0] : UPDATE kode_barang SET stock_item_kode_barang =1894.0000 WHERE kode_barang_id ='5cb8193855ff424';
4 [0] : UPDATE kode_barang SET stock_item_kode_barang =3612.0000 WHERE kode_barang_id ='5cb8193855ff424';
5 [0] : UPDATE kode_barang SET stock_item_kode_barang =1062.0000 WHERE kodebarangid ='5cb81dd2db8f2af';
6 [0] : UPDATE kode_barang SET stock_item_kode_barang =128.0000 WHERE kodebarangid ='5cb8209bb9ad7a0';
7 [0] : UPDATE kode_barang SET stock_item_kode_barang =334.0000 WHERE kodebarangid ='5cb81dd2db8f2af';
8 [0] : UPDATE kode_barang SET stock_item_kode_barang =334.0000 WHERE kodebarangid ='5cb81f9800d5f09';


Sir it's a productions Form, that's why it will generate twice or maybe more and it generate according to the production (PRODUKSI) form
yusa82
 
Posts: 19
Joined: Tue Oct 02, 2018 12:59 pm

Re: How to update one table using two nurunquery before save

Postby yusa82 » Sat May 04, 2019 11:14 am

admin wrote:Guys,

I think the problem is that this PHP code should be in After Save not Before Save.

Steven


Sir, i already use the AFTER SAVE, and it still not working
yusa82
 
Posts: 19
Joined: Tue Oct 02, 2018 12:59 pm

Re: How to update one table using two nurunquery before save

Postby Janusz » Sat May 04, 2019 4:55 pm

Hi, I did following try directly on your application as it was sent and looks that code itself is working proprely. Please verify if you have the same result on your configuration.

Code: Select all
>>>>>>>SET all values=33 to the kode_barang from phpMyAdmin (via SQL)     (related to Data Produksi > PIERCHING 3KG)

UPDATE kode_barang SET stock_item_kode_barang =33 WHERE kode_barang_id ='5cb81dd2dcfc5f7';
UPDATE kode_barang SET stock_item_kode_barang =33 WHERE kode_barang_id ='5cb81f9802c463b';
UPDATE kode_barang SET stock_item_kode_barang =33 WHERE kode_barang_id ='5cb8193855ff424';
UPDATE kode_barang SET stock_item_kode_barang =33 WHERE kode_barang_id ='5cb8193855ff424';
UPDATE kode_barang SET stock_item_kode_barang =33 WHERE kodebarangid ='5cb81dd2db8f2af';
UPDATE kode_barang SET stock_item_kode_barang =33 WHERE kodebarangid ='5cb8209bb9ad7a0';
UPDATE kode_barang SET stock_item_kode_barang =33 WHERE kodebarangid ='5cb81dd2db8f2af';
UPDATE kode_barang SET stock_item_kode_barang =33 WHERE kodebarangid ='5cb81f9800d5f09';

>>>>>> Check values if updated from phpMyAdmin  (all have now value =33)

SELECT stock_item_kode_barang FROM kode_barang WHERE kode_barang_id ='5cb81dd2dcfc5f7';
SELECT stock_item_kode_barang FROM kode_barang WHERE kode_barang_id ='5cb81f9802c463b';
SELECT stock_item_kode_barang FROM kode_barang WHERE kode_barang_id ='5cb8193855ff424';
SELECT stock_item_kode_barang FROM kode_barang WHERE kode_barang_id ='5cb8193855ff424';
SELECT stock_item_kode_barang FROM kode_barang WHERE kodebarangid ='5cb81dd2db8f2af';
SELECT stock_item_kode_barang FROM kode_barang WHERE kodebarangid ='5cb8209bb9ad7a0';
SELECT stock_item_kode_barang FROM kode_barang WHERE kodebarangid ='5cb81dd2db8f2af';
SELECT stock_item_kode_barang FROM kode_barang WHERE kodebarangid ='5cb81f9800d5f09';

==== modify any data from nuBuilder application: Data Produksi > PIERCHING 3KG  and SAVE====

>>>>> Check values if updated by phpMyAdmin  (all have now values different than 33)

SELECT stock_item_kode_barang FROM kode_barang WHERE kode_barang_id ='5cb81dd2dcfc5f7';
SELECT stock_item_kode_barang FROM kode_barang WHERE kode_barang_id ='5cb81f9802c463b';
SELECT stock_item_kode_barang FROM kode_barang WHERE kode_barang_id ='5cb8193855ff424';
SELECT stock_item_kode_barang FROM kode_barang WHERE kode_barang_id ='5cb8193855ff424';
SELECT stock_item_kode_barang FROM kode_barang WHERE kodebarangid ='5cb81dd2db8f2af';
SELECT stock_item_kode_barang FROM kode_barang WHERE kodebarangid ='5cb8209bb9ad7a0';
SELECT stock_item_kode_barang FROM kode_barang WHERE kodebarangid ='5cb81dd2db8f2af';
SELECT stock_item_kode_barang FROM kode_barang WHERE kodebarangid ='5cb81f9800d5f09';

>>>> so it looks that it behaves properly and changing values from both queries
Janusz
 
Posts: 217
Joined: Fri Dec 28, 2018 10:11 pm
Location: Krakow, Poland

Previous

Return to General