Welcome to the nuBuilder Forums!

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

How to update one table using two nurunquery before save

Questions related to using nuBuilder Forte.
kev1n
nuBuilder Team
Posts: 4307
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 447 times
Contact:

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

Unread post by kev1n »

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);
   
}
yusa82
Posts: 19
Joined: Tue Oct 02, 2018 5:29 am

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

Unread post by yusa82 »

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.
kev1n
nuBuilder Team
Posts: 4307
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 447 times
Contact:

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

Unread post by kev1n »

Can you upload your db dump again?
yusa82
Posts: 19
Joined: Tue Oct 02, 2018 5:29 am

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

Unread post by yusa82 »

kev1n wrote:Can you upload your db dump again?
Here is the SQL file sir
You do not have the required permissions to view the files attached to this post.
Janusz
nuBuilder Team
Posts: 506
Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 8 times
Been thanked: 18 times

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

Unread post by Janusz »

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);
}
If you like nuBuilder, please leave a review on SourceForge
Janusz
nuBuilder Team
Posts: 506
Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 8 times
Been thanked: 18 times

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

Unread post by Janusz »

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';
If you like nuBuilder, please leave a review on SourceForge
admin
Site Admin
Posts: 2815
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

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

Unread post by admin »

Guys,

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

Steven
yusa82
Posts: 19
Joined: Tue Oct 02, 2018 5:29 am

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

Unread post by yusa82 »

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 5:29 am

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

Unread post by yusa82 »

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
Janusz
nuBuilder Team
Posts: 506
Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 8 times
Been thanked: 18 times

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

Unread post by Janusz »

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
If you like nuBuilder, please leave a review on SourceForge
Post Reply