Welcome Guest, Not a member yet? Register   Sign In
Is it possible to present a variable before it is actually calculated ?
#1

[eluser]vincej[/eluser]
HI - I know this sounds like a ridiculous contradiction.

On my View page I have a series of operations ( adding / subtracting etc ) which ultimately results in the final calculated result. HOWEVER, I really want the final result to be presented at the top of the page.

Is there anyway I can achieve this ?? In PHP typically a page is read top to bottom.

Many Thanks for all your advice !

#2

[eluser]Otemu[/eluser]
I would just output the result at the top of the page.
You could do your calculations on a controller, create a library or create a helper and then just return the result to the view at the top of the page.

Here a simple example using all the code in the View:
Code:
<html>
<head>
<title>Final Result</title>
</head>
<body>
<?php
       $finalResult = 2 + 2;
       echo $finalResult;
       echo "<br />2+2 = see result above";
?&gt;
&lt;/body&gt;
&lt;/html&gt;
#3

[eluser]LuckyFella73[/eluser]
Following the MVC idea you should better do the calculation
in your controller and pass the result to your view.
#4

[eluser]kanjimaster[/eluser]
<Coughs gently>

In MVC terms this is data manipulation so should be done in a model and be passed by a controller to the view for display anywhere on the page that you'd like. Smile

Or is the real issue here that you don't collect the information for the calculation until further down the page, so that figure at the top is going to be adjusted as the visitor works through the page? If so, your adjustments will need to take place in page using javascript, which doesn't really care where on the page you place your total.
#5

[eluser]LuckyFella73[/eluser]

The main point was to say not to do the calculation in the view.
Without knowing what kind of calculation it's even wrong to to
say all calculation must be made in a model. Depending on what you do
you can do your math in libraries, models, helpers.
Maybe it had been better if I had said: calculation organized by
your controller.
#6

[eluser]vincej[/eluser]
Thanks Guys - The answer is obvious really, I was hoping there was a JQuery like document.ready function which would prevent any operations until the whole page was loaded.

I should move my calculations into the model.

I did think of another easy way: put the result in a div then place the div 'absolutely' anywhere you want.

Many thanks




Theme © iAndrew 2016 - Forum software by © MyBB