Page 1 of 1

SQL - EVAL() help

Posted: Mon Oct 12, 2009 8:04 am
by draw7676
I am attemtpting to execute code, these forumlas, that are stored in a SQL server, but I cannot figure out how to run the code atm.

Code: Select all

Carrier 1                 Carrier 2            Carrier 3                     Carrier 4
(($fuelPrice-1.15)/6)  (($fuelPrice-1.13)/6)  (($fuelPrice-1.10)/6)  (($fuelPrice-1.15)/4.5)
This is the SQL data atm, and what I need to do is execute this code as php. The problem I am running into, is after I do the calls:

Code: Select all

<?php
$fuelStringTable = mssql_query("SELECT CARRIER1, CARRIER2, CARRIER3, CARRIER4 FROM FUEL");
$fuelString = mssql_fetch_array($fuelStringTable, MSSQL_ASSOC);
?>
I cannot figure out how to execute the array of said formulas.
I have tried to use eval(); like this:

Code: Select all

eval("\$x = \"$x\";");
but it does not work.

Essentially, I want to make it so if Carrier 1 was selected, a statement executes as follows:

Code: Select all

$fuelCost = (($fuelPrice-1.15)/6);
Thanks for any help
apologies if I am not descriptive enough.

Re: SQL - EVAL() help

Posted: Mon Oct 12, 2009 8:15 am
by markusn00b
Something like:

Code: Select all

 
// Assuming $algo is the database string to be evaluated.
eval("\$fuelCost = $algo;");
 
Mark.

P.S. Be careful with eval - make sure you're only evaluating clean code.