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

equations using php and / or javascript

Engaged ,
Mar 26, 2012 Mar 26, 2012

i have a excel spreadsheet that has a basic - input one amount in column A then it adds column A to Column C to give Col D results. Well thats the rough idea.,

to basically a field comes from a mysql database then need to start the equation ( the field from the DB would be COL A)

what is the best way to do this?

TOPICS
Server side applications
2.0K
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 ,
Mar 26, 2012 Mar 26, 2012

If the user is simply going to enter a single value and get the results, I would use php. If it's going to be more interactive - like they may try lots of different values, then javascript will provide a better user experience.

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 ,
Mar 26, 2012 Mar 26, 2012

ok it is basically one amount coming from the DB and a fixed equation. What do i need to do to get going on this? are there any good tutorials out there?

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 ,
Mar 26, 2012 Mar 26, 2012

Tutorial? Either I'm not understanding exactly what you need, or you are overthinking this problem. You already know;

1) How to create a form that lets a user pass a value to a script

2) How to retrieve the data from the database into a php variable

3) How to add or perform other mathematical operations on two variables in a php script

4) How to echo results to the screen

What part of this are you having difficulty with?

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 ,
Mar 26, 2012 Mar 26, 2012

3) How to add or perform other mathematical operations on two variables in a php script is the part and maybe i am over complicating it. but the math side of it i dont know

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 ,
Mar 26, 2012 Mar 26, 2012

Jon, what mathematical operation do you want to perform? Can you just type out the expression for us? Just use x and y to represent the data the user enters and the data from the database.

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 ,
Mar 26, 2012 Mar 26, 2012

well i will explain what i am trying to achieve and see if it is more complex than i imagined

the user first selects a property, the monthly rental that they select e.g 98.00 is passed to a column in the database called RENT they then select how long they will be in the property, either 43 or 52 weeks again this information is sent to another field called DURATION

when they log into there page they are given 4 payment options 1 is termly option 2 is loan option 3 is monthly and option 4 is annual

they then select which option they will pay with (the is fixed) they are then directed to the final page where they make the payments for that option.

option 1 is for the 52 weeks

D in pulled in from the database e.g 98.00

E shows =D * 4

F shows =D * 52

G shows a fixed fee e.g 184.00

H shows =E + F + G

I shows =(D*15)+G+E

J shows =D*14

K shows =D*14

L shows =D*9

M showsa = =I+J+K+L

there are 6 tables total 3 for 43 weeks and 3 for 52 weeks

i think if i am shown 1 i can figure the rest out

is this way over my head??

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 ,
Mar 26, 2012 Mar 26, 2012

>is this way over my head??

No. It's much easier than you think. Assuming you have already retrieved the SQL record

$D = $sql_row["montly_rent"];

$E = $D * 4

$F = $D * 52

$G = 184

$H = $E + $F + $G

$I = ($D * 15) + $G + $E

....you get the idea. Of course, use meaningful variable names, not the simple letters I used for an example.

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 ,
Mar 26, 2012 Mar 26, 2012

ok i am going to look at this so the variable would be for example

$monthly = $sql_row["montly_rent"];

$deposit = $monthly * 4

$payable=$monthly *52

>Assuming you have already retrieved the SQL record

you mean the $D record from the database?

so i need to know what goes where. I was going to get  all these variable names into a form to that can be sent off to the DB in order to get the correct figures for the next page.



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 ,
Mar 26, 2012 Mar 26, 2012

>you mean the $D record from the database?

Yes

>so i need to know what goes where.

I thought I just showed you?

>I was going to get  all these variable names into a form to that

>can be sent off to the DB in order to get the correct figures for the next page.

I'm not following you. These are calculated values. Why do you need to send them to the database?

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 ,
Mar 27, 2012 Mar 27, 2012

so i need to know what goes where.

>I thought I just showed you?

but this is the equation, how does this actually get the information to the page?

>I'm not following you. These are calculated values. Why do you need to send them to the database?

ok once the option is selected this figures need to be stored so they can be retrieved on the next page so as to make payment?

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 ,
Mar 27, 2012 Mar 27, 2012

it might be easier to show you the part of the page of what needs to go where

application page this is where the rental price and the duration(actually called weeks) comes from part code ( not all the INSERT ) the rental price comes from another table that is link via the value prop_id)

$insertSQL = sprintf("INSERT INTO plus_signup (prop_id,weeks) VALUES (%s, %s)",

GetSQLValueString($_POST['prop_id'], "text"),

GetSQLValueString($_POST['weeks'], "text"));

form values

<input name="rental_price" type="text" id="rental_price" size="30" readonly="readonly" />

<input type="radio" value="364" name="weeks" />

<input type="radio" value="301" name="weeks" />

the next page is where they chose there option

The Rent and duration are in a table

<td width="162" class="table-text"><?php echo $row_Recordset1['rental_price']; ?></td>

<td class="table-text"><?php echo $row_Recordset1['weeks']; ?></td>

i have then created hidden DIV to show thedifferent values

table is below. this is what i thought needed to be sent to the DB in order to store the values

<table width="980" cellspacing="0" cellpadding="0">

  <tr valign="top">

    <td height="69" bgcolor="#B6EB2B" class="table-text"><div align="center">

      <p>4 weeks</p>

      <p> Security <br />

        Depost</p>

    </div></td>

    <td height="69" bgcolor="#B6EB2B" class="table-text"><div align="center">

      <p>52 weeks </p>

      <p>payable</p>

    </div></td>

    <td height="69" bgcolor="#B6EB2B" class="table-text"><div align="center">Fee</div></td>

    <td height="69" bgcolor="#B6EB2B" class="table-text"><div align="center">

      <p>52 Weeks </p>

      <p>payable<br />

        inc</p>

      <p> fee & SD</p>

    </div></td>

    <td height="69" bgcolor="#B6EB2B" class="table-text"><div align="center">

      <p>Initial</p>

      <p> Holding</p>

      <p> Deposit</p>

    </div></td>

    <td height="69" bgcolor="#B6EB2B" class="table-text"><div align="center">

      <p>Initial </p>

      <p>Payment 15 </p>

      <p>weeks </p>

      <p>15w+f+sd</p>

    </div></td>

    <td height="69" bgcolor="#B6EB2B" class="table-text"><div align="center">

      <p>Balance </p>

      <p>due </p>

      <p>before </p>

      <p>moving in</p>

    </div></td>

    <td height="69" bgcolor="#B6EB2B" class="table-text"><div align="center">

      <p>Second </p>

      <p>payment </p>

      <p>14 weeks</p>

    </div></td>

    <td height="69" bgcolor="#B6EB2B" class="table-text"><div align="center">

      <p>Third </p>

      <p>Payment </p>

      <p>14 weeks</p>

    </div></td>

    <td height="69" bgcolor="#B6EB2B" class="table-text"><div align="center">

      <p>Fourth </p>

      <p>payment </p>

      <p>9 weeks</p>

    </div></td>

    <td bgcolor="#B6EB2B" class="table-text">Total Payment</td>

  </tr>

  <tr>

    <td height="38" colspan="11" align="center"><form name="form1" method="post" action="">

      <table width="100%" border="0" cellspacing="0" cellpadding="5">

        <tr>

          <td><table width="100%" cellspacing="0" cellpadding="0">

            <tr>

              <td align="center"><div align="center">

                <input name="SecDeposit" type="text" size="8" />

                <br />

              </div></td>

            </tr>

            <tr>

              <td height="30"><div align="center"></div></td>

            </tr>

          </table></td>

          <td><table width="100%" cellspacing="0" cellpadding="0">

            <tr>

              <td align="center"><div align="center">

                <input name="WeeksPayable" type="text" size="8" />

                <br />

              </div></td>

            </tr>

            <tr>

              <td height="30"><div align="center"></div></td>

            </tr>

          </table></td>

          <td><table width="100%" cellspacing="0" cellpadding="0">

            <tr>

              <td align="center"><div align="center">

                <input name="Fee" type="text" size="8" />

                <br />

              </div></td>

            </tr>

            <tr>

              <td height="30"><div align="center"></div></td>

            </tr>

          </table></td>

          <td><table width="100%" cellspacing="0" cellpadding="0">

            <tr>

              <td align="center"><div align="center">

                <input name="FeeIncl" type="text" id="BalanceDue8" size="8" />

                <br />

              </div></td>

            </tr>

            <tr>

              <td height="30"><div align="center"></div></td>

            </tr>

          </table></td>

          <td><table width="100%" cellspacing="0" cellpadding="0">

            <tr>

              <td align="center"><div align="center">

                <input name="HoldingDep" type="text" size="8" />

                <br />

              </div></td>

            </tr>

            <tr>

              <td height="30"><div align="center"></div></td>

            </tr>

          </table></td>

          <td><table width="100%" cellspacing="0" cellpadding="0">

            <tr>

              <td align="center"><div align="center">

                <input name="Initial" type="text" size="8" />

                <br />

              </div></td>

            </tr>

            <tr>

              <td height="30"><div align="center"></div></td>

            </tr>

          </table></td>

          <td><table width="100%" cellspacing="0" cellpadding="0">

            <tr>

              <td align="center"><div align="center">

                <input name="MovBal" type="text" size="8" />

                <br />

              </div></td>

            </tr>

            <tr>

              <td height="30"><div align="center"></div></td>

            </tr>

          </table></td>

          <td><table width="100%" cellspacing="0" cellpadding="0">

            <tr>

              <td align="center"><div align="center">

                <input name="SecPay" type="text" size="8" />

                <br />

              </div></td>

            </tr>

            <tr>

              <td height="30"><div align="center"></div></td>

            </tr>

          </table></td>

          <td><table width="100%" cellspacing="0" cellpadding="0">

            <tr>

              <td align="center"><div align="center">

                <input name="thirdPay" type="text" size="8" />

                <br />

              </div></td>

            </tr>

            <tr>

              <td height="30"><div align="center"></div></td>

            </tr>

          </table></td>

          <td><table width="100%" cellspacing="0" cellpadding="0">

            <tr>

              <td align="center"><div align="center">

                <input name="fourthPay" type="text" size="8" />

                <br />

              </div></td>

            </tr>

            <tr>

              <td height="30"><div align="center"></div></td>

            </tr>

          </table></td>

          <td><table width="100%" cellspacing="0" cellpadding="0">

            <tr>

              <td align="center"><div align="center">

                <input name="fullpayment" type="text" size="8" />

                <br />

              </div></td>

            </tr>

            <tr>

              <td height="30"><div align="center"></div></td>

            </tr>

          </table></td>

        </tr>

      </table>

    </form></td>

  </tr>

</table>

i need to add a submit button

but the thing is they have even chosen 43 or 52 weeks so should i make a table (total of 6 for each option)

and we have the equations

$monthly = $sql_row["montly_rent"];

$deposit = $monthly * 4

$payable=$monthly *52 and so on...

how do i get this working to show in the tables

we then have the final screen where they make the payments

it will be the same as the above table but under Balance Due, second payment, third payment and fourth payment there will be a pay button.

Also this needs to be deducted off the total when payments are made

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 ,
Mar 27, 2012 Mar 27, 2012

>but the thing is they have even chosen 43 or 52 weeks so should i make a table (total of 6 for each option)

I'm not sure what you are saying. 6 what?

>how do i get this working to show in the tables

You simply use the echo construct within the table cell to output the variable's value.

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 ,
Mar 27, 2012 Mar 27, 2012

>I'm not sure what you are saying. 6 what?

sorry 6 actual options and six tables 3 for each weeks option

>You simply use the echo construct within the table cell to output the variable's value.

right i sort of understand this but have no clue on how to do it

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 ,
Mar 27, 2012 Mar 27, 2012

>>I'm not following you. These are calculated values. Why do you need to send them to the database?

>ok once the option is selected this figures need to be stored so they can be retrieved on the next page so as to make payment?

Store the selected option in a session variable. Then do the calculations on the payment page. You can then store the options they select in the database when the payment is made. But you almost never want to store calculated values in the database.

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 ,
Mar 27, 2012 Mar 27, 2012
LATEST

>Store the selected option in a session variable. Then do the calculations on the payment page. You can then store the options they select in the database when the payment is made. But you almost never want to store calculated values in the database.

Again this is what i dont know how to do, i dont know what goes where

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