Skip to main content
Topic solved
This topic has been marked as solved and requires no further attention.
Topic: Running Multiple Quries using Dynamic Table Row (Read 3738 times) previous topic - next topic

Running Multiple Quries using Dynamic Table Row

Hi all
Is it possible to run multiple queries as a result of dynamic table row.
For example When I add three records using dynamic table row . A query should executed for each record (After add record) . I tried but a single query is executed for first record.

Re: Running Multiple Quries using Dynamic Table Row

Reply #1
@maumar‍ it is possible, you have to do a loop on the variable holding the record. In the loop, you then make your query for each.

 

Re: Running Multiple Quries using Dynamic Table Row

Reply #2
Dear @willvin
I have used this query on Execute Before Adding Records

$db->where("wh_item", $modeldata['product']);
$db->where("category", $modeldata['category']);
$wh_quantity = $db->getValue("whstock", "wh_quantity");

and this one for after adding records
$table_data = array(
    "wh_quantity" => $wh_quantity + $modeldata['qty']
);
$db->where($row = 1);
$db->where("wh_item", $modeldata['product']);
$db->where("category", $modeldata['category']);
$db->update("whstock", $table_data);

$table_data = array(
    "wh_quantity" => $wh_quantity + $modeldata['qty']
);
$db->where($row = 2);
$db->where("wh_item", $modeldata['product']);
$db->where("category", $modeldata['category']);
$db->update("whstock", $table_data);


Please guide how can i do that


Re: Running Multiple Quries using Dynamic Table Row

Reply #3
@maumar‍ it should be this way since you said you are using Dynamic Table Row.
Code: [Select]
foreach($allmodeldata as $loopdata){
    $db->where("wh_item", $loopdata['product']);
    $db->where("category", $loopdata['category']);
    $wh_quantity[] = $db->getValue("whstock", "wh_quantity");
}

And this one for after adding records
Code: [Select]
for($i=0; $i<count($allmodeldata); $i++){
    $table_data = array(
        "wh_quantity" => $wh_quantity[$i] + $allmodeldata[$i]['qty']
    );

    $db->where("wh_item", $allmodeldata[$i]['product']);
    $db->where("category", $allmodeldata[$i]['category']);
    $db->update("whstock", $table_data);
}

Enjoy ;) .

Re: Running Multiple Quries using Dynamic Table Row

Reply #4
@willvin  Thanks a lot it worked perfectly. 

Re: Running Multiple Quries using Dynamic Table Row

Reply #5
@maumar
 
may i know your detail database, so i can learn too.

i'm trying to create a simple stock in and stock out app,
the table as follow:

items
-------
*id
item_name
item_stock

stock_in
---------
*id
stock_in_date

stock_in_detail
---------------
stock_in_id
item_id
stock_in_qty

Thank You

Re: Running Multiple Quries using Dynamic Table Row

Reply #6
Hello @willvin   My SQL data

Suggestion Needed

Tables

table - items
fields - id,quote_no,charge,rate,qty

table-quote
fields - id,quote_no,client_name,remarks
--------------------
Master Form - quote
Sub Form - Items
--------------------

Page Events AfterAdd in quote form
for ($i = 0; $i < count($allmodeldata); $i++) {
    $table_data = array(
        "id" => $id[$i] + $allmodeldata[$i]['id'],
        "charge" => $charge[$i] + $allmodeldata[$i]['charge'],
        "rate" => $rate[$i] + $allmodeldata[$i]['rate'],
        "qty" => $qty[$i] + $allmodeldata[$i]['qty']
    );
   
    $db->where("id", $allmodeldata[$i]['id']);
    $db->update("item", $table_data);
}

----------------------------------------------------

Suggest me Errors message in submitting data .

Thanks
Bhaskar