Welcome to the nuBuilder Forums!
Join our community by registering and logging in.
As a member, you'll get access to exclusive forums, resources, and content available only to registered users.
Questions related to using nuBuilder Forte.
yusa82
Posts: 19 Joined: Tue Oct 02, 2018 5:29 am
Unread post
by yusa82 » Thu Apr 18, 2019 5:15 am
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: 4568 Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 76 times
Been thanked: 532 times
Contact:
Unread post
by kev1n » Thu Apr 18, 2019 7:38 am
If each query is executed separately, does it work?
yusa82
Posts: 19 Joined: Tue Oct 02, 2018 5:29 am
Unread post
by yusa82 » Thu Apr 18, 2019 8:27 am
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: 4568 Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 76 times
Been thanked: 532 times
Contact:
Unread post
by kev1n » Thu Apr 18, 2019 8:40 am
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
Unread post
by yusa82 » Thu Apr 18, 2019 9:17 am
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: 4568 Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 76 times
Been thanked: 532 times
Contact:
Unread post
by kev1n » Thu Apr 18, 2019 9:42 am
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
Unread post
by yusa82 » Thu Apr 18, 2019 9:47 am
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: 2829 Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 30 times
Unread post
by admin » Sat Apr 20, 2019 12:44 am
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
Unread post
by yusa82 » Sat Apr 20, 2019 4:05 pm
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
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
yusa82
Posts: 19 Joined: Tue Oct 02, 2018 5:29 am
Unread post
by yusa82 » Sun Apr 21, 2019 7:50 am
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.