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

How to update one table using two nurunquery before save

Unread post by yusa82 »

Hi, i would like to update one table with two query before save, one of the query works, but when i add other query, it can't work.
Here is the code

Code: Select all

$y = "update `kode_data_barang` inner JOIN
(
SELECT
    kode_data_barang.*,
    raw_produksi.*

FROM
    kode_data_barang,
    raw_produksi
) d
ON kode_data_barang.kode_data_barang_id = `raw_material`
set kode_data_barang.kode_item_data_barang_stock = `raw_sisa_stock`";
$u = nuRunQuery($y);

$s = "update `kode_data_barang` inner JOIN
(
SELECT
    kode_data_barang.*,
    barang_produksi.*

FROM
    kode_data_barang,
    barang_produksi
) d
ON kode_data_barang.kode_data_barang_id = `barang_produksi`
set kode_data_barang.kode_item_data_barang_stock = `total_stock_produksi`";
$a = nuRunQuery($s);
Can anyone help me please?
kev1n
nuBuilder Team
Posts: 4305
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 446 times
Contact:

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

Unread post by kev1n »

If each query is executed separately, does it work?
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:If each query is executed separately, does it work?
Yes sir it works, i test each query and it works, but when i put two query like the code, it doesn't work
kev1n
nuBuilder Team
Posts: 4305
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 446 times
Contact:

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

Unread post by kev1n »

What if you execute both statements at the same time with one call to nuRunQuery()?
(Add a semicolon after each statement)
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:What if you execute both statements at the same time with one call to nuRunQuery()?
(Add a semicolon after each statement)
How do i do that sir?
kev1n
nuBuilder Team
Posts: 4305
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 446 times
Contact:

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

Unread post by kev1n »

I was thinking of something like this:

Code: Select all

// 1st update query
$q1 = "update `kode_data_barang` inner JOIN
(
SELECT
    kode_data_barang.*,
    raw_produksi.*

FROM
    kode_data_barang,
    raw_produksi
) d
ON kode_data_barang.kode_data_barang_id = `raw_material`
set kode_data_barang.kode_item_data_barang_stock = `raw_sisa_stock`";

// 2nd update query
$q2 = "update `kode_data_barang` inner JOIN
(
SELECT
    kode_data_barang.*,
    barang_produksi.*

FROM
    kode_data_barang,
    barang_produksi
) d
ON kode_data_barang.kode_data_barang_id = `barang_produksi`
set kode_data_barang.kode_item_data_barang_stock = `total_stock_produksi`";

$a = nuRunQuery($q1.";".$q2);
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 was thinking of something like this:

Code: Select all

// 1st update query
$q1 = "update `kode_data_barang` inner JOIN
(
SELECT
    kode_data_barang.*,
    raw_produksi.*

FROM
    kode_data_barang,
    raw_produksi
) d
ON kode_data_barang.kode_data_barang_id = `raw_material`
set kode_data_barang.kode_item_data_barang_stock = `raw_sisa_stock`";

// 2nd update query
$q2 = "update `kode_data_barang` inner JOIN
(
SELECT
    kode_data_barang.*,
    barang_produksi.*

FROM
    kode_data_barang,
    barang_produksi
) d
ON kode_data_barang.kode_data_barang_id = `barang_produksi`
set kode_data_barang.kode_item_data_barang_stock = `total_stock_produksi`";

$a = nuRunQuery($q1.";".$q2);
No sir, still not working
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 »

yusa82,


You could try doing it this way...

Code: Select all



$s	= "SELECT * FROM raw_produksi";
$t	= nuRunQuery($s);

while($r = db_fetch_object($t)){
	
	$s	= "UPDATE kode_data_barang SET kode_data_barang_id = '$r->raw_sisa_stock' WHERE data_id = '$r->raw_material' ";
	
	nuRunQuery($s);
	
}


$s	= "SELECT * FROM barang_produksi";
$t	= nuRunQuery($s);

while($r = db_fetch_object($t)){
	
	$s	= "UPDATE kode_data_barang SET kode_data_barang_id = '$r->total_stock_produksi' WHERE kode_data_barang_id = '$r->barang_produksi' ";
	
	nuRunQuery($s);
	
}


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 »

admin wrote:yusa82,


You could try doing it this way...

Code: Select all



$s	= "SELECT * FROM raw_produksi";
$t	= nuRunQuery($s);

while($r = db_fetch_object($t)){
	
	$s	= "UPDATE kode_data_barang SET kode_data_barang_id = '$r->raw_sisa_stock' WHERE data_id = '$r->raw_material' ";
	
	nuRunQuery($s);
	
}


$s	= "SELECT * FROM barang_produksi";
$t	= nuRunQuery($s);

while($r = db_fetch_object($t)){
	
	$s	= "UPDATE kode_data_barang SET kode_data_barang_id = '$r->total_stock_produksi' WHERE kode_data_barang_id = '$r->barang_produksi' ";
	
	nuRunQuery($s);
	
}


Steven
No sir, it still not working
Here is the screen shoot before save
Image

As the Stock Tersedia should update from Sisa Stock
And Stock Produksi from Total Stock Produksi
And after i save it, then try to browse the items, it's not updating
Image
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 »

Maybe someone can help me?
here is the SQL file, i'm really confused where did i do wrong with the query
You do not have the required permissions to view the files attached to this post.
Post Reply