Variable Variables using Database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Suhendri
Forum Newbie
Posts: 11
Joined: Tue Jan 06, 2004 7:14 pm
Location: Tangerang, Indonesia
Contact:

Variable Variables using Database

Post by Suhendri »

How to implement the variable variables with PHP using database.

When i using hard coded variable variables, its no problem.
Example:
$var1 = 10;
$var2 = 20;
$formula = $var1 * 100 / $var2;
print $formula;

How to implement like sample above, if the variables from fields.
Let say i have 1 table with the field: var1, var2 and formula.

When i try implement the sample:

print $rec['var1']; // printed : 10
print $rec['var2']; // printed : 20
print $rec['formula']; // printed : var1 * 100 / var2 (printed as text not the value from the calculation).

What i want is, i want to implement like the sample above. I have tried "eval" but it doesn't work.

Please i need help from all of yours...


Thank's
mwong
Forum Commoner
Posts: 34
Joined: Sun Dec 28, 2003 2:58 am

Post by mwong »

Maybe the value in the table has to be:

$rec['var1'] * 100 / $rec['var2']

Then possibly eval that? It seems to me if you just have:

var1 * 100 / var2

That doesn't mean anything really.....there are no "$" in front of the var1 / var2 so it doesn't know what to do with it.
Post Reply