How to update data using JS code?

QuestionsHow to update data using JS code?
C3media asked 3 years ago

How to update row using MySQL query for example.

Thank you!

1 Answers
C3media answered 3 years ago

Resolved using http://www.phpgrid.org/faqs/#71 (How to post row using JS), after used on_after_insert event to load function that update row field so:

function update_award_points($data)
{

//1: Select Client ID to start query
$client_id = $data["params"]["customer_id"];

global $h;
$res = $h->execute_query("select id, name, company, award_points from sma_companies WHERE id = '$client_id'");
#phpgrid_error($h->con->errormsg());
$arr = $res->GetRows();
#phpgrid_error($arr);
$points = $arr[0]["award_points"];

//2: Query 1 – If statement is in case sale type Buy (Bonus) for example TRUE, then subtraction award_points 180 points
if($sale == 'Bonus'){
$accrued = $points – 180;
$h->execute_query("UPDATE sma_companies SET award_points = '$accrued' WHERE id = '$client_id'");

//3: Query 3 – sale type different then FALSE
} else {
$acu = $puntos + $t;
$h->execute_query("UPDATE sma_companies SET award_points = '$accrued' WHERE id = '$client_id'");
}

Regards!

Your Answer

16 + 0 =

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 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

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

Let us improve this post!

Tell us how we can improve this post?