SQL - EVAL() help

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
draw7676
Forum Newbie
Posts: 2
Joined: Mon Oct 12, 2009 7:40 am

SQL - EVAL() help

Post 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.
User avatar
markusn00b
Forum Contributor
Posts: 298
Joined: Sat Oct 20, 2007 2:16 pm
Location: York, England

Re: SQL - EVAL() help

Post 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.
Post Reply