Page 1 of 1

calculate a php class with a new variable

Posted: Wed Mar 27, 2013 8:34 am
by jonnyfortis
I am not sure what a class is. i have a page already written that has classes in place for equations. I have made some new variables for some new equation but am getting incorrect results, I basically need to multiple / divide / subtract these prebuilt classes against my new variable

this is what i have so far

Code: Select all

<?php
                                $utilityHost = 21.0;
                                $col4 = $option_two->amount_due_before - $option_two->four_weeks_security - $option_two->fee;
                                $col5 = $col4 / $row_Recordset1['rental_price'];
                                $col3 = $utilityHost * $col5;
                                $col6 = $row_Recordset1['rental_price'] * $col5;
                                ?>



$col4 is the variable using the pre built classes.

all of these are being echoed out into a table

e.g

Code: Select all

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


the classes

Code: Select all

<?php
 
require_once('../lib/PaymentOptionOne.php');
                        require_once('../lib/PaymentOptionTwo.php');
                        require_once('../lib/PaymentOptionThree.php');
                        require_once('../lib/PaymentOptionFour.php');
 
     $rent = $row_Recordset1['rental_price'];
                        if($row_Recordset1['weekly_rate'] != 0.00)
                            $rent = $row_Recordset1['weekly_rate'];
                        $weeks = $row_Recordset1['weeks'] / 7;
 
                                                            $query = "SELECT * FROM editprop WHERE prop_id = %s";
                                                            $query = sprintf($query, GetSQLValueString($row_Recordset1['prop_id'], "text"));
                                                            $results = mysql_query($query);
                                                            while($row = mysql_fetch_array($results))
                                                            {
                                                                      $option_three_rent = $row['rental_price_monthly'];
                                                                      if(empty($option_three_rent))
                                                                      {
                                                                                $option_three_rent = $rent;
                                                                      }
                                                            }
                        $option_one = new PaymentOptionOne($rent, $weeks);
                        $option_two = new PaymentOptionTwo($rent, $weeks);
                        $option_three = new PaymentOptionThree($option_three_rent, $weeks);

thanks in advance

Re: calculate a php class with a new variable

Posted: Wed Mar 27, 2013 1:10 pm
by requinix
1. Echo out all the variables and see their exact values.
2. Try the math out yourself to get the right answer.
3. Take the formula(e) and put them in PHP code.

To that end, (a) what are the sample values you're using to test with and (b) how do you calculate the answer?

Also, where is the code that actually gets those values into the variables? Is that where the problem is?

Also, what have you checked so far? Do you have error_reporting and display_errors settings set appropriately for a development environment? Any warnings or error messages?

You've posted a bit of stuff but it's not enough to see the full picture.

Re: calculate a php class with a new variable

Posted: Thu Mar 28, 2013 6:03 am
by jonnyfortis
To that end, (a) what are the sample values you're using to test with and (b) how do you calculate the answer?
i have been doing lots of testing and am not getting errors, just in correct values.

so for example
the value that are being echoed out from

Code: Select all

$option_two->amount_due_before is 1492.8 (this is correct)
$option_two->four_weeks_security is 328.00 (again correct)
$option_two->fee is 184.80 (again correct)
$row_Recordset1['rental_price'] is 82.00 (again correct)
the table i have made to echo out

Code: Select all

                                $utilityHost = 21.0;
                                $col4 = $option_two->amount_due_before - $option_two->four_weeks_security - $option_two->fee;
                                $col5 = $col4 / $row_Recordset1['rental_price'];
                                $col3 = $utilityHost * $col5;
                                $col6 = $row_Recordset1['rental_price'] * $col5;
is

Code: Select all

amount to LL                                                                        <?php  echo "£" . number_format($row_Recordset1['rental_price'] - $utilityHost);  ?>....this is showing 61.00 (correct)
Utility +6 to Host                                                                   <?php echo "£" . $utilityHost; ?>....this is showing 21.00 (correct)
Money to Host multipled by weeks to Carl                               <?php echo "£" . $col3; ?>.....this is showing £250.9756097561 (should be showing 84.00)
Equation                                                                               <?php echo "£" . $col4; ?>..... this is showing 980.00 (this should be showing 84.00)
Amount due moving in - 4 weeks security deposit - fees           <?php echo "£" . $col5; ?>.....showing 11.951219512195 (should be showing 4.00)
Weeks To Carl                                                                        <?php echo "£" . $col6; ?>.....showing 980.00 (should be 244.00)
i know the correct results because the orginal calculation are from an excel spreadsheets
Also, what have you checked so far?
i have tried variations of wrapping $option_two->amount_due_before in quotes on each option and without
Do you have error_reporting and display_errors settings set appropriately for a development environment?
no error reporting because it looks like just incorrect values
Any warnings or error messages?
no non

does this make my problem clearer?

Re: calculate a php class with a new variable

Posted: Thu Mar 28, 2013 12:47 pm
by requinix
$col4 is the easiest to look at.
this is showing 980.00 (this should be showing 84.00)

Code: Select all

$col4 = $option_two->amount_due_before - $option_two->four_weeks_security - $option_two->fee;
1492.80 - 328.00 - 184.80 most definitely = 980.00 so I'm not sure how you think it's supposed to be 84.00. Apparently the formula you have there is wrong.

Re: calculate a php class with a new variable

Posted: Thu Mar 28, 2013 3:52 pm
by jonnyfortis
so as an equation
$col4 = $option_two->amount_due_before - $option_two->four_weeks_security - $option_two->fee;
should work?

Re: calculate a php class with a new variable

Posted: Thu Mar 28, 2013 5:15 pm
by requinix
That's something only you can answer. The math clearly says that 980 is the correct answer but you say it is not so I'm not sure what to make of that. My best guess is that you have the wrong equation, either in the code or in the spreadsheet.

Re: calculate a php class with a new variable

Posted: Fri Mar 29, 2013 12:17 pm
by Christopher
jonnyfortis wrote:I am not sure what a class is. i have a page already written that has classes in place for equations.

Code: Select all

<?php
                                $utilityHost = 21.0;
                                $col4 = $option_two->amount_due_before - $option_two->four_weeks_security - $option_two->fee;
                                $col5 = $col4 / $row_Recordset1['rental_price'];
                                $col3 = $utilityHost * $col5;
                                $col6 = $row_Recordset1['rental_price'] * $col5;
                                ?>
You didn't show the code to the class. One thing I notice is that you are really just using the class as an array and not doing OOP. You should really be following "Tell Don't Ask" with this code. Show the class code and some example input values with the expected outputs. Then maybe we can help.