Page 1 of 1

Insurance Quote - Redirect Page After Calculation?

Posted: Sun May 17, 2009 4:54 pm
by Sjwdavies
Hi guys, i've a tricky problem to solve.

I work for an Insurance Broker and have been given the task of building an internal quote system. I've got the pages built to capture the quote details, and have built two functions - one for each insurer, only two at the minute. However, because there's so many MySQL statements necessary, the price page, which calls the functions then displays the prices, takes several seconds to load.

What's the best way to create a holding page - you know the sort, insurance sites, holiday sites, etc use them.

They capture the necessary details, then you click 'Go', then you see a page saying 'Please wait while we search for your holiday' then you get redirected?

Obviously, I can't use the Header("Location: ...") because the headers are already output...

The only solution I can thinkk of is to use a Javascript OnLoad function that calls the function page (which calculates the price), then use a Javascript redirect when the pages have been run?

I've been racking my brains trying to think of a way to do this, anyone got any ideas or suggestions?

Re: Insurance Quote - Redirect Page After Calculation?

Posted: Sun May 17, 2009 6:32 pm
by califdon
I'm confused by your questions. You're asking about several different things that don't seem to have anything to do with each other. Your Subject refers to a redirect page and you asked about that. If that's what you need to do, you might look into the use ob_start and ob_flush to buffer the output until you're ready to send everything at once. But I don't really see what you're trying to do. Why don't you just do your calculations in the same script that sends back the page with the results? I don't know what you mean by a "holding page." My guess is that something else is responsible for your slow time of calculation. I don't know much about insurance fee calculations, but it's hard to imagine anything so complicated that one query to a properly constructed database schema wouldn't produce the result in the time it takes to execute one query. Perhaps if you showed us the SQL statements you're using, we might have some suggestions for you.

Re: Insurance Quote - Redirect Page After Calculation?

Posted: Sun May 17, 2009 7:24 pm
by Zoxive
I am going to take a different route, and say for example this is a very complex query, and it would not be optimized more (coder/hardware limited).

The next best thing I would do is make use of Javascript/Xml(ajax). To help me out with JavaScript i use the framework mootools (other common ones include jquery and prototype).

I can't really think of the words to explain, so I will try and explain with some example code.
(Keep in mind this is just an example to hopefully get you on the right track)

The loading page

Code: Select all

<html>
<head>
  <script src="mootools-1.2.2-core-yc.js" type="text/javascript"></script>
  <script type="text/javascript">
    window.addEvent('domready', function(){
      var req = new Request({
        url: 'query.php',
        <!-- URL is the page that will be doing all the work, it will be loaded in the background -->
        onSuccess: function(data){
        <!-- the "data" var is the html/xml/text or what ever format you want that is returned from the request, in my case its a text -->
          if(data == 'TRUE'){
        <!-- my simple check to see if it loaded successfully, in this example it will always return TRUE 
         In your case you will want a javascript page reload or redirect function here
         -->
            $('divname').set('text','LOADED!!');
          }else{
            <!-- fail 1 = The script did not output correctly -->
            failed(1);
          }
        },
        onFailure: function(){
          <!-- fail 2 = the request function failed -->
          failed(2);
        }
      }).send();
      <!-- with the send() command it submits the request, since i wanted to this on page load i added it at the end of the code here
      I could of also added it to a button with
      $('buttonid').addEvent('click', function(){
        req.send();
    });
      -->
 
    function failed(num){
      $('divname').set('text','Problem');
    }
 
    });
  </script>
</head>
<body>
  <div id="divname">
  Loading...  
  <!-- I wouldn't suggest having the loading text/graphic here already, make the JavaScript put it here when the query actually starts -->
  </div>
</body>
</html>
 
query.php (Just a simple sleep like its doing something for 3 seconds)

Code: Select all

<?php
 
sleep(3); // Sleep 3 seconds
echo 'TRUE';
 
Hopefully that wasn't to confusing, just trying to point you in the right direction, and I haven't posted here in quiet a while.

Re: Insurance Quote - Redirect Page After Calculation?

Posted: Mon May 18, 2009 3:02 am
by Sjwdavies
Let me try and make this clearer....

Data Capture
This page captures all the insurance quote details, building value, stock, etc...

Price Page
This page displays the price. Currently, it calls the functions part way through the page. This is where the problem lies. Because of the complexity of the functions, they cause a pause while the page is loading.

If you have a look yourself on some of the online holiday sites, after you input your details your presented with a pretty 'holding page' that says please wait while we search for you...


@Zoxive: I've been experimenting with Ajax recently (calling a postcode checker function to check a postcode/zipcode when a user clicks out of the box) and was thinking that maybe I could use Ajax again to call the functions. What i was thinking was storing all the form data in a session array, then call the calculation page and simply return a quoteId or something..... eventually all the quotes will be stored in a database for tracking purposes, so returning simply the quoteId would be sufficient.

Is this the best method, or should I look into using cURL for example?

Re: Insurance Quote - Redirect Page After Calculation?

Posted: Mon May 18, 2009 3:20 pm
by Zoxive
cURL would basically be doing the same thing as your include of the file. (Well not exactly, but it would get the output of what ever php returned, usually text).

cURL is used for sending data to a remote website/server. At my last job I actually used ajax to send the request for the (php page to do the) cURL job. Because the request would take upwards of 5 seconds and I did not want that to reflect on our page load time.

For this case i think the use of Ajax to get the price data without affecting the initial page load would be the best option. And your idea about using sessions on the first page to save all the data would definitely work, just make sure theres some type of timestamp or other identifying number just encase the same user happens to have more the one window open.

Edit: Fixed some wording issues.

Re: Insurance Quote - Redirect Page After Calculation?

Posted: Mon May 18, 2009 4:16 pm
by Sjwdavies
Thanks for the positive comments.

What I think might be best, is to have the data capture page get all the details, then submit to a page that simply says 'Loading...'. Then, at the very end of that page, store all the $_POST variables from the previous page in a $_SESSION['quoteDetails'] array. Then, the Ajax will call a php file that completes the calculation, stores the quote details and quote prices in the database, then passes the quote ID back to the loading page to signify the calculation was completed successfully. This in turn, can the be used as a $_GET on the end of the javascript redirect to goto the Show Prices where the prices can be pulled back from thedatabase.

I'd rather not store the results in a session array for numerous reasons, one of which being that the page will be used as an 'edit' page also, meaning I can't simply reply on the data being stored on $_SESSION variables...

That all make sense?