This topic is locked
[SOLVED]

 Writing View As Custom Result To Field

2/3/2021 10:12:42 AM
PHPRunner General questions
S
salus1 authorDevClub member

Hi,
I configured a Price field using View As Custom with the following...
$cuttype = urlencode($data["cuttype"]);

$value = file_get_contents("https://www.valucalc.com/pricequery3.php?CutType=$cuttype&Weight=".$data["weight"]."&Quality=".$data["quality"]."&Color=".$data["color";])
...that inserts $data[""] variables into a URL that fetches values from an external database.
Editable example at https://xlforms.net/orderform/lookup_list.php
My question today is how do I write the displayed value to the underlying Price field in the database?
Thanks!

admin 2/3/2021

If you need to update the database every time this field is displayed you can use Database API for this purpose:

https://xlinesoft.com/phprunner/docs/db_update.htm

S
salus1 authorDevClub member 2/3/2021

Geez, is it really that simple? Unreal.

$cuttype = urlencode($data["cuttype"]);

$orderid = $data["orderid"];

$value = file_get_contents("https://www.valucalc.com/pricequery3.php?CutType=$cuttype&Weight=".$data["weight"]."&Quality=".$data["quality"]."&Color=".$data["color";]);

$data = array();

$keyvalues = array();

$data["price"] = $value;

$keyvalues["orderid"] = $orderid;

DB::Update("lookup", $data, $keyvalues );

$number = $value;

$formatter = new NumberFormatter('en_US', NumberFormatter::CURRENCY);

return $formatter->formatCurrency($number, 'USD');


Thanks!