Skip to main content
Inspiring
March 27, 2013
Answered

calculate a php class with a new variable

  • March 27, 2013
  • 1 reply
  • 757 views

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

<?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

<?php

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

?>

<?php

echo "£" . $utilityHost;

?>

the classes

<?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

This topic has been closed for replies.
Correct answer bregent

>multiple my variable with the classes that are already in place

Classes are complex constructs that hold data structures and methods. You don't multiple a variable with a class - you can reference a variable within that class or object. What exactly is the problem you are having with this?

This syntax should work (note that I'm just using arbitrary variables:


$col4 = $option_two->amount_due_before * $col2

I think it is critical that you become familiar with object oriented coding if you are going to be working with it.

http://www.elated.com/articles/object-oriented-php-for-absolute-beginners/

1 reply

Participating Frequently
March 27, 2013

What is it that you want to do? Why are you using object oriented constructs if you don't understand them?

Inspiring
March 28, 2013

>>What is it that you want to do?

multiple my variable with the classes that are already in place

>>Why are you using object oriented constructs if you don't understand them?

these are not mine, this part was built by someone else.

bregentCorrect answer
Participating Frequently
March 28, 2013

>multiple my variable with the classes that are already in place

Classes are complex constructs that hold data structures and methods. You don't multiple a variable with a class - you can reference a variable within that class or object. What exactly is the problem you are having with this?

This syntax should work (note that I'm just using arbitrary variables:


$col4 = $option_two->amount_due_before * $col2

I think it is critical that you become familiar with object oriented coding if you are going to be working with it.

http://www.elated.com/articles/object-oriented-php-for-absolute-beginners/