chgav007
chgav007

Reputation: 55

display database value as a math operation as a PHP variable if value is stored in database using prefix $

I have a table named parameters where I have inserted a value like '$counter_sales+$counter_sales' in one column. Now in my PHP page I have fetched values from that table. When I am trying to echo something like $row10['column_name'] then it is only giving me result as '($counter_sales+$counter_sales)' but I want as its value as eg. 24000 to be displayed which actually I have mentioned for eg. say 12000 in variable $counter_sales in above line in same page. Is it possible ? Please help me. Actually want to code like that. In my table parameters there is a value '($counter_sales+$counter_sales)' and I want to use it like assigned value as mentioned in code.

<?php                                                                       
$depart=1;
while($row10 = mysqli_fetch_assoc($selectedalldepartment))
{
    $sqlsel1 = "select * from parameters ";
    $sqlsel1q = mysqli_query($conn,$sqlsel1);
    $row2 = mysqli_fetch_assoc($sqlsel1q);
    //assigned counter sales value
    $counter_sales  = $row2["counter_sales"];
    ?>
    <tr>
        <td style="text-align:center;"><?php echo $depart; ?></td>
        <td style="text-align:center;"><?php echo $row10["incentive"] ; ?></td>
    </tr>
    <?php
    $depaz++;
    $depart++;
}
?>

Here is my table:

  user_id  |  user_name  |  incentive
     1     | Goldy Shahu | ($counter_sales+$counter_sales)

Upvotes: 2

Views: 114

Answers (2)

Phil
Phil

Reputation: 4069

You should be able to use eval

http://php.net/manual/en/function.eval.php

Upvotes: 0

AbraCadaver
AbraCadaver

Reputation: 78994

The obvious way that may be dangerous, especially if anything may be stored in the column:

<?php eval("echo {$row10['incentive']};"); ?>

Upvotes: 2

Related Questions