Hi I have a php page that requests a part number, then displays some information about that part from database, such as name, description, quantity in stock and related pdf file. Every thing works fine, apart from the fact that when it is waiting for quantity in stock number to be displayed, the whole page stays blank for a few seconds that might give the reader the impression that there has been some mistake and confuse them. Now what I can't understand is why it doesn't display the html data, while it waits for the rest of data to be fetched? i tried to use some javascript function that tells user data is gettign ready but it doesn't seem to work. Ay ideas please, as I have worked on this for some time. here is the php file I use: <? include ("../includes/validate_search.php"); ?> <html> <link href="../css/form.css" rel="stylesheet" type="text/css" /> <?php include("../includes/head_cart_wp.php"); ?> <body > <?php include("../includes/js_counter.php"); ?> <table border="0" cellspacing="0" cellpadding="0" align="center"> <tr> <td align="center"> <?php include ("../includes/box3_link.php"); ?> <tr> <td> </td> </tr> <tr> <td> </td> </tr> <form name = "database" method="POST" action=" <? echo $PHP_SELF;?>"> <tr> <td class="pd_header"> Please Enter xxx Part Number : <input type="text" class="pd_header" name="partnumber" value="<? echo $partnumber;?>"> <br> <a class="pd_report" href="mailto:xxxx@xx.com?subject=Feedback for xxx.com&body=Hi%0A %0A The following xxx Part Number produced the wrong pdf file.%0A %0A Part Number: ">Incorrect pdf? Report here.</a> <input type="submit" name="submit" value="search" > <br ><br > </td> </tr> </form> </table> <br /> <?php print("<font size=\"1\" face=\"Arial\" color=\"#002675\" >" ); if (!isset($_POST['partnumber']) || trim($_POST['partnumber']) == '' || trim($_POST['partnumber']) == "%") { die(); } elseif (!(validate_user($_POST["partnumber"]))) { echo "Validation failure\n"; } else { mysql_connect('xxx.co.uk', 'xxx', 'xx') or die(mysql_error()); mysql_select_db("xx") or die(mysql_error()); $partnumber=$_REQUEST['partnumber']; print("<font size=\"3\" face=\"Arial\" color=\"#002675\" >" ); $result = mysql_query(" SELECT * FROM xxx WHERE part_number = '$partnumber' ") or die(mysql_error()); //If not in database, exit if (mysql_num_rows($result) ==0) { echo"No such part number, please try again"; exit; } $row = mysql_fetch_array( $result ); // Print out the contents of each row into a table $pdf = mysql_query( " SELECT * FROM pn_quark WHERE part_number ='" . $row['part_number'] . "'") or die(mysql_error()); $rowpdf = mysql_fetch_array($pdf); ?> <table border='1' align='center' class='pd_header2'> <tr> <th >Part Number</th> <th>Description</th><th>Quantity in Stock</th><th >Price (£)</th><th>Pdf</th> </tr> <tr ><td align="center"> <?php echo $row['part_number']; ?> </td><td align=\"center\"> <?php echo $row['disc']; ?> </td><td align="center" style="color:red"> <?php include("../includes/multi.php");?> </td><td align="center"> <?php echo $row['price_each1']; ?> </td><td align=\"center\"> <a target=\"_blank\" href=\"../C28reduced/C28 <?php echo "$rowpdf[page_number]" ?>.pdf "><img class="pdf" src="../images/pdflogo.gif"></a> </td></tr> <tr> <td align="center" class="pd_ticker" height="56" colspan="5"> <script language="JavaScript1.2"> <!-- <?php include("../includes/ticker.php"); ?> // --> </script> </td> </tr> <tr> <td colspan="4" class="pd_trade_mark"> All trademarks acknowledged. All Rights Reserved. Copyright © 2009 x x Ltd</td></tr> </table> <?php } print("</font>"); ?> </body> </html> Code (markup): Thanks in advance.
Hi Thanks for your reply. I put flush() command at the top of the page but is still has afew seconds of delay in a white screen. the problem is the line <?php include("../includes/multi.php");?> Code (markup): . The multi.php is a pice of code, written by some one else that gets data from our server that checked the stock level and delay built into the code. Now I don't mind the delay, as long as the rest of the code above it is displayed and the user doesn't think something has gone wrong and click away. So why doesn't the graphics before it gets displayed? Any help is much appreciated.
flush() is quirky to use. You should read through the flush() page at php.net. In my experience you need to send some whitespace to flush the browser buffer. You may also need to use obflush(). Code should be something like this: <?php function something_that _takes_a_long_time { blah; blah: blah; } // taken from php.net (I think) - flushes browser buffer function push_the_buffer { for($i = 0; $i < 40000; $i++) { echo ' '; // extra spaces } // keeps it flowing to the browser… flush(); // 50000 microseconds keeps things flowing in safari, IE, firefox, etc usleep(50000); } // start writing to screen push_the_buffer(); echo "This may take a while. Can I get you a doughnut while you wait?"; flush(); something_that_takes_a_long_time(); ?>