![]() |
Is it possible to present a variable before it is actually calculated ? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Is it possible to present a variable before it is actually calculated ? (/showthread.php?tid=52589) |
Is it possible to present a variable before it is actually calculated ? - El Forum - 06-17-2012 [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 ! Is it possible to present a variable before it is actually calculated ? - El Forum - 06-18-2012 [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> Is it possible to present a variable before it is actually calculated ? - El Forum - 06-18-2012 [eluser]LuckyFella73[/eluser] Following the MVC idea you should better do the calculation in your controller and pass the result to your view. Is it possible to present a variable before it is actually calculated ? - El Forum - 06-18-2012 [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. ![]() 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. Is it possible to present a variable before it is actually calculated ? - El Forum - 06-18-2012 [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. Is it possible to present a variable before it is actually calculated ? - El Forum - 06-18-2012 [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 |