Save data in two different tables at same time using on_after_insert method

QuestionsSave data in two different tables at same time using on_after_insert method
C3media asked 3 years ago

Hello I have two Tables:

1. Clients (ID, Name, Points)

2. Sales (ID_Clients, Product (10, for example), …)

After Sales registering, I need it update Points Col in Clients table limit 90, using method on_after_insert based in ID_Clients col and ID in Clients table.

When Points in clients > 90, update to Zero (0) to start cicle again.

I tried using Views in Mysql but It´s with bugs and very bad option…

Thanks by your help!

9 Answers
Abu Ghufran answered 3 years ago

It should work with on_after_insert.
If you email me code, i can suggest the changes.

C3media answered 3 years ago

Hello Abu,

This is working with basic update on_after_insert method:

function bonus_data($data)
{

$t = $data["params"]["reference_no"];
$client_id = $data["params"]["customer_id"];
global $h;
$h->execute_query("UPDATE sma_companies SET award_points = '$t' WHERE id = '$client_id'");
}

I would like to update award_points using previously If or Case statements, If award_points < 180 then points = award_points + award_points else then set to zero.

Thank you

C3media answered 3 years ago

Hello Abu,

I´m trying with this function:

function bonus_data($data)
{
$t = $data["params"]["reference_no"];
$client_id = $data["params"]["customer_id"];
global $h;
$h->execute_query("select award_points from sma_companies WHERE id = '$client_id'");
$puntos = $h;

if ($puntos < "180") {
$t=$data["params"]["reference_no"];
global $h;
$h->execute_query("UPDATE sma_companies SET award_points = '$t' + '$puntos' WHERE id = '$client_id'");
}
else
if ($puntos > "180")
{
$t=$data["params"]["reference_no"];
global $h;
$h->execute_query("UPDATE sma_companies SET award_points = '$t' WHERE id = '$client_id'");
}
}

This is updating award_points Col, but I need Sum award_points to previous value until award_points > 180.

Thanks by your help!

Abu Ghufran answered 3 years ago

You can put these IF conditions in php code and run different update queries.

C3media answered 3 years ago

Abu, I need this to load on_after_insert method, It´s possible right now but just updating previous values. So I need select the Previous Col to update accumulating data.

Thank you by your help!

Abu Ghufran answered 3 years ago

I understand now, you can change query to:

$res = $h->execute_query("select award_points from sma_companies WHERE id = '$client_id'");
$arr = $res->GetRows();
$puntos = $arr["award_points"];

C3media answered 3 years ago

Ok Abu,

Phpgrid_error is:

<tr id="FormError">

It´s not taking row data, this is the problem!

Thanks by tour help

C3media answered 3 years ago

Show me this:

Uncaught TypeError: Cannot read property 'id' of undefined

Thank you!

C3media answered 3 years ago

Issue resolved by remote

Your Answer

6 + 7 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating / 5. Vote count:

We are sorry that this post was not useful for you!

Let us improve this post!