Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

multiply php to fixed values

Engaged ,
Nov 01, 2012 Nov 01, 2012

Hello

i need to find out how to make some calculation in php, i have an output table on a page that has values (prices) that need to be be multiplied and divided by set values.

for example

This value <?php echo $row_Recordset1['rental_price']; ?>

needs to be multiplied by a set value of 21.00 then show the results

i take it the set value (21.00) would be stored as a value then echoed into a table then you would do something like this

<?php echo $row_Recordset1['rental_price']; * echo_value?>

but each result needs to be shown as an equation

bit lost

thanks

TOPICS
Server side applications
2.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Nov 14, 2012 Nov 14, 2012

store the mulitplied value into a variable and then echo that variable.

for Ex.

<?php

$multiplied_value=$row_Recordset1['rental_price']*echo_value

echo $multiplied_value;

?>

Thanks

Harshit

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 14, 2012 Nov 14, 2012

thanks, bit how do i store the set value of 21.00 ?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Nov 14, 2012 Nov 14, 2012

$echo_value=21.0;

PHP will save it as float.

If you want to typecast it you can alos do that.

$new_echovalue = (float) $echo_value;

$new_echovalue=21.0;

Thanks

Harshit

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 14, 2012 Nov 14, 2012

ok so the whole thing would look like this

(e.g rental value - 95.00)

<?php

$echo_value=21.0;

$multiplied_value=$row_Recordset1['rental_price']*echo_value

echo $multiplied_value;

?>

21.0 * 95 would be displayed

is this correct?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 14, 2012 Nov 14, 2012

No, it's not correct, as you would find out if you tested it in a browser. To be honest, your description of what you want is rather confusing. You begin by saying you need to make a calculation in PHP, but then say the result needs to be displayed as an equation. If you want the result displayed as an equation, there's no calculation.

If you simply want the equation, this is what you need:

$echo_value = 21;

echo "$echo_value * {$row_Recordset1['rental_price']}";

If you want both the result of the calculation and the formula, you need this:

$echo_value = 21;

echo number_format($echo_value * $row_Recordset1['rental_price']) . " ($echo_value * {$row_Recordset1['rental_price']})";

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 14, 2012 Nov 14, 2012

hello, yes i was a bit unclear what i needed to achieve, basically i have a excel spreadsheet i need to duplicate. that has the equations in the cells and certain cells are mulitplied togeather, subtracted added then showing the final value, so i needed to know how to store the relevent information. thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 15, 2012 Nov 15, 2012

ok, as i explained in a earlier post, i have a table and am trying to duplicate a excel spreadsheet. i have managed to do the basic equations you showed me but how to i add equations togeather. i have examples below

this is the excel spreadsheet and hopefully to make it clearer in brackets i have included the cell number in the spreadsheet

(C23 = set figure e.g 97.00)

(D8 - set figure e.g 97.00)

col 1   (P23)                       col 2   (Q23)                  col 3    (R23)                          col 4 (S23)                     col 5 (T23)                  col 6  (U23)

=SUM(C23-Q23)            set figure e.g 21.00          =SUM(Q23*T23)                  =SUM(G23-E8-G8)         =SUM(S23/D8)            =SUM(P23*T23)

what i have so far is on my code is ( i have put it underneath each other so it can fit)

col 1

<?php

                                $utilityHost = 21.0;

echo "£" . number_format($row_Recordset1['rental_price'] - $utilityHost);

                                ?>

col 2

<?php

              echo "£" . $utilityHost;

                                ?>

i need to know how to show a = figure then be able to use that for the next equation.

i think then i can work the rest out

thanks in advance

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 15, 2012 Nov 15, 2012

i missed to excel equations out

E8 = is D8 * 4

G8 = set fee of 184.80

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 15, 2012 Nov 15, 2012

I don't really follow what you're trying to do, but PHP is capable of performing calculations. All you need to do is to remove the =SUM().

For example, if you use the cell numbers as your variables, you could use the following:

echo $C23 - $Q23;

That would display the result of subtracting Q23 from C23. Of course, you can also use number_format() to format the output.

Is that what you're after? Or is it something more complex?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 15, 2012 Nov 15, 2012

sorry if that wasnt clear in my explaination looking at the above doesnt look how it should.. I understand  the calculations it showing the results in a way that them results can then be used for the next equation, does that make sense?

for example

$utilityHost = 21.0;

value1 (set figure e.g) 95.00 * $utilityHost = show results . then the results of the previous equation * another equation = a new figure

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 15, 2012 Nov 15, 2012

If you don't need to keep the results of a calculation, you can simply display the results like this:

$a = 5;

$b = 10;

echo $a * $b; // displays 50

However, if you need to reuse the result of a calculation, you need to store it in a variable:

$a = 5;

$b = 10;

$calc1 = $a * $b;

echo $calc1; // displays 50

echo $calc1 * $a; // displays 250

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 19, 2012 Nov 19, 2012
LATEST

thanks so much for your help so far. im getting there.

i have my equations setup but am getting negative values. basically i have some varialble that i have to included (e.g $option_one->balance_due_before) but im not sure if these are stored correctly in my new variables i have set up

this is what i have so far

$utilityHost = 21.0;

$col3 = $utilityHost * $col5;

$col4 = $option_one->balance_due_before - $option_one->four_weeks_security - $option_one->fee;

$col5 = $col4 / $row_Recordset1['rental_price'];

$col6 = $row_Recordset1['rental_price'] * $col5;

variable $option_one->balance_due_before is echoed on the page in another area £<?php echo $option_one->balance_before ?>

this is also the same for $option_one->four_weeks_security and $option_one->fee

the results are echoed for the following variables below

echo "£" . number_format($row_Recordset1['rental_price'] - $utilityHost);

echo "£" . $utilityHost;

echo "£" . $col3;

echo "£" . $col4;

echo "£" . $col5;

echo "£" . $col6;

i think it must be $col4 must be causing the incorrect results

can you help?

thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines