Hello.
Probably pretty easy stuff, but can't figure it out:
I have a string list of variables, for instance:
$vars = '$a1,$a2,$a3';
which I would like to pass to list() -function:
list($vars) = $db->sql_fetchrow($result)
Of cours now $vars gets the value from the query, but what I would like list to have is:
list($a1,$a2,$a3) = $db->sql_fetchrow($result)
Any idea how I could output the contents of $vars to the list() -function?
Thanks,
Tom
Problem passing variables to functions.
Moderator: General Moderators
-
tpotman777
- Forum Newbie
- Posts: 9
- Joined: Wed Nov 11, 2009 5:06 am
Re: Problem passing variables to functions.
I think the only way to do this is with eval().
-
tpotman777
- Forum Newbie
- Posts: 9
- Joined: Wed Nov 11, 2009 5:06 am
Re: Problem passing variables to functions.
Umm, how could I implement that in my code?jackpf wrote:I think the only way to do this is with eval().
Re: Problem passing variables to functions.
Something like:
I think.
Code: Select all
$vars = '$a1,$a2,$a3';
eval('list('.$vars.') = $db->sql_fetchrow($result);');-
tpotman777
- Forum Newbie
- Posts: 9
- Joined: Wed Nov 11, 2009 5:06 am
Re: Problem passing variables to functions.
Ok, looks reasonable! I actually also have 'while' -statement in there, but just can't get the syntax right:
eval('while list('.$vars.') = $db->sql_fetchrow($result){ echo "something"; }');
gives: Parse error: syntax error, unexpected T_LIST, expecting '('
Any clues on that?
Thanks!
Tom
eval('while list('.$vars.') = $db->sql_fetchrow($result){ echo "something"; }');
gives: Parse error: syntax error, unexpected T_LIST, expecting '('
Any clues on that?
Thanks!
Tom
jackpf wrote:Something like:I think.Code: Select all
$vars = '$a1,$a2,$a3'; eval('list('.$vars.') = $db->sql_fetchrow($result);');
-
tpotman777
- Forum Newbie
- Posts: 9
- Joined: Wed Nov 11, 2009 5:06 am
Re: Problem passing variables to functions.
Ok, got it working, thanks for your help!
-T
-T
tpotman777 wrote:Ok, looks reasonable! I actually also have 'while' -statement in there, but just can't get the syntax right:
eval('while list('.$vars.') = $db->sql_fetchrow($result){ echo "something"; }');
gives: Parse error: syntax error, unexpected T_LIST, expecting '('
Any clues on that?
Thanks!
Tom
jackpf wrote:Something like:I think.Code: Select all
$vars = '$a1,$a2,$a3'; eval('list('.$vars.') = $db->sql_fetchrow($result);');