This topic is locked

how to decrease by 1 a field when using $DAL

5/2/2017 1:30:56 PM
PHPRunner General questions
jgeorgiou author

when i add a record to transaction table (using lookup to chhose article from articles table)

i want While saving the transaction to update quantity of articles table (to decrease quantity of articles table)
code should be like (before record added event)
global $dal;

$tblitems = $dal->Table("articles");

$tblitems->Param["article"]= $values['transaction_article'];

$tblitems->Value["quantity"]=$values["quantity"] - value["transaction_quantity"]; ???? this doesnt work

(what should i use here for quantity field to get decreased by a field at transaction table named "transaction_quantity"?)

$tblitems->Update();

jgeorgiou author 5/2/2017

$tblitems->Value["quantity"]=$values["quantity"] - value["transaction_quantity"]; ???? this doesnt work
when i use

$tblitems->Value["quantity"]= ++$values["quantity"];
it icreases by 1 in right way , why i can't make an add or subtract?

lefty 5/2/2017



$tblitems->Value["quantity"]=$values["quantity"] - value["transaction_quantity"]; ???? this doesnt work
when i use

$tblitems->Value["quantity"]= ++$values["quantity"];
it icreases by 1 in right way , why i can't make an add or subtract?



You need custom query for this
$sql = "update Users set active=0 where id=32";

CustomQuery($sql);

jgeorgiou author 5/4/2017

I dont get it

Can you be more specific for my case?

L
laonian 5/4/2017



$tblitems->Value["quantity"]=$values["quantity"] - value["transaction_quantity"]; ???? this doesnt work
when i use

$tblitems->Value["quantity"]= ++$values["quantity"];
it icreases by 1 in right way , why i can't make an add or subtract?


You have several syntax errors in your coding:
Value["quantity"]-> $values["quantity"] // appeared twice

value["transaction_quantity"] -> $values["transaction_quantity"]

jgeorgiou author 5/5/2017

You have several syntax errors in your coding:
Value["quantity"]-> $values["quantity"] // appeared twice

value["transaction_quantity"] -> $values["transaction_quantity"]
i will make it more clear
Value["detailtb_quantity"]-> $values["mastertb_quantity"]

value["detailtb_transaction_quantity"] -> $values["mastertb_transaction_quantity"]
can i calculate with 2 or more fields?

if not with $DAL , how can i do it with customSQL? (PHPRUNNER/MySQL)

L
laonian 5/5/2017

You need to provide more info if you want replies to be more specific. For example, the full name of your article table, how you want the quantity field in the table updated, the relation between your transaction table and article table, etc, this would be helpful for others to write specific code for you.

jgeorgiou author 5/6/2017

thanks for reply , let me explain more.
when i add a record to transaction table (using lookup to choose article from articles table)

i want While saving the transaction to update quantity of articles table
code should be like (before record added event)
global $dal;

$tblitems = $dal->Table("articles");

$tblitems->Param["articles_articlename"]= $values['transaction_article'];

$tblitems->Value["articles_quantity"]=$values["transaction_qtytotal"] - $values["transaction_quantity"]; ???? this doesnt work

$tblitems->Update();
(what should i use to Value["articles_quantity"] for quantity field to get set calculated?
PS

Phprunner/Mysql

lefty 5/6/2017



thanks for reply , let me explain more.
when i add a record to transaction table (using lookup to choose article from articles table)

i want While saving the transaction to update quantity of articles table
code should be like (before record added event)
global $dal;

$tblitems = $dal->Table("articles");

$tblitems->Param["articles_articlename"]= $values['transaction_article'];

$tblitems->Value["articles_quantity"]=$values["transaction_qtytotal"] - $values["transaction_quantity"]; ???? this doesnt work

$tblitems->Update();
(what should i use to Value["articles_quantity"] for quantity field to get set calculated?
PS

Phprunner/Mysql


This needs to go after record added as the values have not been added to database yet if use before add.

global $dal;

$tblarticles = $dal->Table("articles");

$tblarticles->Param["articles_articlename"]= $values['transaction_article'];

$tblarticles->Value["articles_quantity"]=($values["transaction_qtytotal"] - $values["transaction_quantity"]);

$tblarticles->Update();

jgeorgiou author 5/7/2017

yes , i have used before ADD event

I will try to move it to after ADD event
thanks for answer , i will make it and i will come back to make the thread "solved" if it works.