How to update one table using two nurunquery before save

Questions related to using nuBuilder Forte.

How to update one table using two nurunquery before save

Postby yusa82 » Thu Apr 18, 2019 12:45 pm

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?
yusa82
 
Posts: 19
Joined: Tue Oct 02, 2018 12:59 pm

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

Postby kev1n » Thu Apr 18, 2019 3:08 pm

If each query is executed separately, does it work?
kev1n
 
Posts: 242
Joined: Mon Oct 15, 2018 2:13 am

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

Postby yusa82 » Thu Apr 18, 2019 3:57 pm

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
yusa82
 
Posts: 19
Joined: Tue Oct 02, 2018 12:59 pm

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

Postby kev1n » Thu Apr 18, 2019 4:10 pm

What if you execute both statements at the same time with one call to nuRunQuery()?
(Add a semicolon after each statement)
kev1n
 
Posts: 242
Joined: Mon Oct 15, 2018 2:13 am

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

Postby yusa82 » Thu Apr 18, 2019 4:47 pm

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?
yusa82
 
Posts: 19
Joined: Tue Oct 02, 2018 12:59 pm

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

Postby kev1n » Thu Apr 18, 2019 5:12 pm

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);
kev1n
 
Posts: 242
Joined: Mon Oct 15, 2018 2:13 am

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

Postby yusa82 » Thu Apr 18, 2019 5:17 pm

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
yusa82
 
Posts: 19
Joined: Tue Oct 02, 2018 12:59 pm

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

Postby admin » Sat Apr 20, 2019 8:14 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
admin
Site Admin
 
Posts: 3108
Joined: Mon Jun 15, 2009 9:53 am

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

Postby yusa82 » Sat Apr 20, 2019 11:35 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
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 12:59 pm

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

Postby yusa82 » Sun Apr 21, 2019 3:20 pm

Maybe someone can help me?
here is the SQL file, i'm really confused where did i do wrong with the query
Attachments
oci(1).zip
SQL File
(156.44 KiB) Downloaded 21 times
yusa82
 
Posts: 19
Joined: Tue Oct 02, 2018 12:59 pm

Next

Return to General