/    Sign up×
Community /Pin to ProfileBookmark

inside a variable have multiple variables from database

//$row[formula] fetching from database and the store value is: ($basic – $advance)

$basic=100;
$advance=75;
echo $result= $row[formula];

// my output comes like this “($basic + $advance)”
and i want it come like this (100 – 75)

please help

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@simplypixieJan 02.2013 — I am not entirely sure what you mean as you are not displaying all of your code and don't explain what $row[formula] does or how it is used.

To echo the variables:
[code=php]echo '('.$basic.' - '.$advanced.')';[/code]
Copy linkTweet thisAlerts:
@ApniGangauthorJan 03.2013 — $basic=100;

$advance=75;

$row[formula]= ($basic - $advance) // this comes from database


when i echo "($basic - $advance)"; //my output comes (100 - 75)

but i echo "$row[formula]"; // then my output comes ($basic - $advance)


and i want when i echo $row[formula] my result will come=> (100 - 75);
Copy linkTweet thisAlerts:
@NogDogJan 03.2013 — Make sure you are showing us the exact code, as each of these will give you different results (note the difference in how the expressions are quoted):
[code=php]
$foo = 8;
$bar = 9;

echo ($foo - $bar); // -1
echo '($foo - $bar)'; // ($foo - $bar)
echo "($foo - $bar)"; // (8 - 9)
[/code]
Copy linkTweet thisAlerts:
@ApniGangauthorJan 03.2013 — $foo = 8;

$bar = 9;

thanks for reply

but this one is store in a variable -> ($foo - $bar);

example $a=($foo - $bar);

now when i echo $a my result is coming ($foo - $bar)

but i want when i echo $a it will show like (9 - 8);



note ($foo - $bar); is store in a variable // a=($foo - $bar);
Copy linkTweet thisAlerts:
@simplypixieJan 03.2013 — NogDog has just given you the answer to this! So to use in your case you need to use the version
[code=php]echo "($basic - $advance)"; // (100 - 75) [/code]
Copy linkTweet thisAlerts:
@ApniGangauthorJan 04.2013 — [code=php]
$basic = 500;
$fetch[amount]= "($basic * 10 / 100)";
$fetch[advance]="($basic * 10 / 100) + ($advance * 5 / 100) ";

$advance = str_replace('$basic', $basic, $fetch['amount']);
$advance= calculate_string($advance); // and is 50
echo $x = str_replace('$advance', $advance, $fetch['advance']);
// echo result (500 * 10 / 100) + ( * 5 / 100)
[/code]


$advance is missing
×

Success!

Help @ApniGang spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...