auto update value function

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
randy
User
Posts: 20

auto update value function

Post by randy »

trying to create a global function to auto update value from another table. How do I pass the value of foreign key from current record being inserted/edited. The code below picks up the value correctly if value is from within function. No help available for Currentpage(), $this->$rsnew["xxx"]; doesn't work.

Code below.....

function get_cals(){

$idnut = $rsnew["idnuts"]; //not working
//this works $idnut= 8;

function getCalVal($idnut){
$linker = @mysqli_connect("localhost", "root", "root", "nuts");

if (!$linker) {
die('Connect Error: ' . mysqli_connect_error());
}
$query = "SELECT Calories FROM nut_val WHERE id = " . $idnut or die("Error in the consult.." . mysqli_error($link));
$resultx = $linker->query($query);
$rowx = mysqli_fetch_array($resultx);
$result = $rowx["Calories"];
return $result;
}
$result = getCalval($idnut);
return $result;
}


mobhar
User
Posts: 11737

Post by mobhar »

Double check your code. You cannot insert a function inside another function.


randy
User
Posts: 20

Post by randy »

But it works. Tried it out except as before can't pass values to function.


mobhar
User
Posts: 11737

Post by mobhar »

Then you only need to put your code inside "Row_Inserted" server event. No need to use global code for such case.


mobhar
User
Posts: 11737

Post by mobhar »

Alternatively, you may use a session variable to catch the value.


randy
User
Posts: 20

Post by randy »

Thank you, mobhar. The first I can do, just wanted to reuse it at multiple places. The second is currently beyond me, will try it out.


Post Reply