Page 1 of 2

How to update one table using two nurunquery before save

PostPosted: Thu Apr 18, 2019 12:45 pm
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?

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

PostPosted: Thu Apr 18, 2019 3:08 pm
by kev1n
If each query is executed separately, does it work?

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

PostPosted: Thu Apr 18, 2019 3:57 pm
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

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

PostPosted: Thu Apr 18, 2019 4:10 pm
by kev1n
What if you execute both statements at the same time with one call to nuRunQuery()?
(Add a semicolon after each statement)

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

PostPosted: Thu Apr 18, 2019 4:47 pm
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?

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

PostPosted: Thu Apr 18, 2019 5:12 pm
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);

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

PostPosted: Thu Apr 18, 2019 5:17 pm
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

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

PostPosted: Sat Apr 20, 2019 8:14 am
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

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

PostPosted: Sat Apr 20, 2019 11:35 pm
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

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

PostPosted: Sun Apr 21, 2019 3:20 pm
by yusa82
Maybe someone can help me?
here is the SQL file, i'm really confused where did i do wrong with the query