[SOLVED] dynamic variable how to ????

Hi,

I would like to use field name in variable , I do this but I’ve an error (unexpected {… ) :

function calcprice($noline){

$price=“PRICE_”.$noline; // fields price_1, price_2, … price_10 exists in my form

{$price} = $value ;

}

Thanks in advance
Can

{$price} is not allowed. {} is refering to a field variable. So I fear that you have to process each field separately. It’s not a safe habit to use php this way and it would mean that you can interpret php within a php variable… Not sure, but afaik it’s not allowed (any more).

Thank you Albert…

Hi,
as Albert mentioned already, you can’t use the field names in a variable.
An option would be to call your fields by reference and not by name but I don’t know if it is suitable for your situatioin.
Anyhow, here it is.

Create an array of your field addresses (may be in the onLoad event)
[pricearray] = array(&{price_1}, &{price_2}, you get the picture…); // the &-parameter stores the address of a field/variable

And somewhere down the road

function calcprice($nonline)
{
//you could do your array definition here as well, than you don’t need a global variable
[pricearray][$nonline] = $value; //don’t forget that the array starts at 0
}

I think this should do the trick.

jsb

Thanks Jsb

It’s works !!!