You are here: Re: Variables in Variables? « PHP « IT news, forums, messages
Re: Variables in Variables?

Posted by Ben on 10/04/07 11:32

Marquez Design said the following on 11/18/2005 04:54 PM:
> Greetings.
>
> Does anyone know how to do this?
>
> I have,
>
> $var
>
> $var2
>
> In a field called two_vars in a MySQL db.
>
> I am calling the variables inside PHP document.
>
> In that document I am saying:
>
> $var = "time"
> $var2 = "clock"
>
> <!-- I do the query in MySQL here -->
>
> echo "$two_vars";
>
> But the what prints out is
>
> $var
>
> $var2
>
> not "time" and "clock". I know that is what is in the database, but I want
> it to replace the variables when printed in the PHP file.
>
> Does this make sense to anyone? Does anyone know how to do this?

If I understand your question properly I'd explode $two_vars with
whatever seperator you have between them and then you'll need to use
eval to get your results. Maybe something like...


$dbVars=explode(',',$two_vars); // Assuming comma seperator
foreach($dbVars AS $key => $value) {
$eval="\$temp=".$value.";";
eval($eval);
echo $temp;
}

- Ben

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация