Fieldname definied by a variable

Hi everybody,

assumed we have the situation, that a form contains 10 fields called

field1,
field2,
field…,
field10.

On an event (for example “onRefresh”) we write a php-procedure, that checks each value of the mentioned fields. Cause of the big amount we do not want to write for each field an own procedure, rather something like this:

for ($i = 1; $i <= 10; $i++)
{
if ({field}$i = “Hello”) // that’s probably the wrong syntax!
{
sc_error_message(“Goodbye” . {Field}$i); // that’s probably the wrong syntax!
}
}

Who can tell the right syntax to adresse a fieldname, that is combined as a string??

Thx in advance,

Hydro

Re: Fieldname definied by a variable

If you have a look at sc_lookup(), it shows you how you can access a record and it assigns it to an array for numeric access. Since you already have the fields/values in the form, this may be an extra call you do not want to the table just to access by array. { field } is already broken down, so your approach would not work as suspected.

The other approach is to create an array yourself using DB schema a select command and then cycle through them as needed.

Regards,
Scott.

Re: Fieldname definied by a variable

I didn?t read your entire post, but I can tell you that the upper code is wrong, if you want to access a certain value on an array you must use [$i]. Another big mistake is the “=” operator, in PHP you must use == or === if you want to compare two values.

So your code must be rewritten as follows

if ({field}[$i] == “Hello”)
{
sc_error_message(“Goodbye” . {Field}[$i]);
}

Re: Fieldname definied by a variable

{field} is already a string, unless you mean {table} from sc_lookup()

{table[0][0]} for the first field on the first row

{field}[0] would return a letter, correct?

Regards,
Scott.