This topic is locked

nid help how to perform operation

5/24/2008 6:20:15 AM
PHPRunner General questions
M
madcat820 author

good day,

hope someone helps....
inventory(TABLE NAME)

id

itemname

itemstocks
order(TABLE NAME)

id

order-name

order-name-howmany

withdraw_by
basically what i wanted is

  1. when "add new" in "ORDER" table, i will choose 1 item from INVENTORY (itemname=order-name)
  2. upon choosing name, i will input how many i will subtract/withdraw (order-name-howmany)
  3. finally when clicking "save" in "add new", it will do the operation of ("itemstocks" = "itemstocks" - "order-name-howmany")

    ITEMSTOCKS which is in INVENTORY table. however im inside ORDER table "ADD NEW" so im clueless how to make it work...
    MY CODE, which is i think not working
    function BeforeAdd(&$values,&$message,$inline)

    {
    // Parameters:

    // $values - Array object.

    // Each field on the Add form is represented as a 'Field name'-'Field value' pair
    //** Custom code ****

    // put your custom code here
    global $conn;

    $str="SELECT * FROM inventory WHERE itemname='".$values['order-name']."'";

    $values["order-name-howmany"] = $values["order-name-howmany"] - $values["itemstocks"];

    db_exec($str,$conn);
    return true;
    // return true if you like to proceed with adding new record

    // return false otherwise
    thank you and more power.



kujox 5/25/2008

i would like to ask for help regarding this 2 tables, in ""order"" table and INVENTORY table, if i add a record on order, i will select 1 ITEMNAME which is a ITEMNAME from inventory table, and i will input how many it will subtract (withdraw) which is ITEMSTOCKS from INVENTORY TABLE. so if bulb has 10 stocks(ITEMSTOCKS), and if withdraw 1, it will became 9.

i showed my visual editor so someone can help me with the right and proper codes. as i know i have to put the codes on "before record added" but don't know how and what to put.
in short words, im asking for subtraction operation code.
and also, how do i update the table inventory eg.bulb_01 from 10 stocks to 9 stocks? when im adding a record within inside of "order add page" thank you so much...


Try this, you may have to change the names to reflect your table data
$sql = "SELECT * FROM inventory WHERE ITEMNAME =" . $values['ITEMNAME'];

$rs = db_query($sql,$conn);

$data=db_fetch_array($rs)

$new_value = $data['ITEMSTOCKS'] - $values['order_qty'];
$sql = "UPDATE inventory SET ITEMSTOCKS =".$new_value." WHERE ITEMNAME =" . $values['ITEMNAME];

db_exec($sql,$conn);

M
madcat820 author 5/25/2008

im sorry , im completely noob to this, it gives me an error
Parse error: syntax error, unexpected T_VARIABLE in D:\xammp\htdocs\output101\include\order_events.php on line 39
my code
global $conn;

$str="SELECT * FROM inventory WHERE itemname='".$values['order-name']."'";

$rs = db_query($str,$conn);

$data=db_fetch_array($rs)
$new_value = $data['itemstocks'] - $values['order-name-howmany'];

$sql = "UPDATE inventory SET itemstocks='".$new_value." WHERE itemname='".$values['order-name']."'";

db_exec($sql,$conn);
-----
do i have to add new fields in the visual editor or???
i have tried every syntax and possible code combination but i still get

Parse error: syntax error, unexpected T_VARIABLE in D:\xammp\htdocs\output101\include\order_events.php on line 34
i need help =( im still newbie in this...
ps. i have edited my help request, im sorry, uve answered when your about to post

M
madcat820 author 5/25/2008

ok, i got it working thank you so much for helping.