graham23s Posted April 24, 2008 Share Posted April 24, 2008 HI gUys, on the shopping cart page i have coded, then i while loop out the order details the page is lagging them times out, but if i comment out the while loop it loads normally! full page: <?php // standard header // print("<div class=\"subheader\"><div id=\"title\">Home > <span class=\"blue\">Confirm > Step 2</span></div>Confirm below that your order is correct before proceeding to payment.</div>"); // vars // $shipping_address_old = $_POST['ship_old']; $shipping_address_new = $_POST['ship_new']; $payment_method = $_POST['payment_method']; // do some error checking and grab the details from the users post // if(isset($shipping_address_old) && isset($shipping_address_new)) { standard_message("Error","You can only select 1 shipping address."); } if(!isset($shipping_address_old) && !isset($shipping_address_new)) { standard_message("Error","You never selected a shipping address."); } if(!isset($payment_method)) { standard_message("Error","You never selected a payment method."); } // the step replace with an image // print("<h1></h1>"); // if the old shipping is set grab those details // if(isset($shipping_address_old)) { // then grab all the shipping info // $ship_old_title = $_POST['co_title']; $ship_old_first_name = $_POST['co_first_name']; $ship_old_last_name = $_POST['co_last_name']; $ship_old_address = $_POST['co_street']; $ship_old_city = $_POST['co_city']; $ship_old_code = $_POST['co_code']; $ship_old_country = $_POST['co_country']; $ship_old_county = $_POST['co_state_county']; $ship_old_contact_number = $_POST['co_number']; } // if the new shipping is set grab those details // // then grab all the shipping info // $ship_new_title = $_POST['co_title_new']; $ship_new_first_name = $_POST['co_first_name_new']; $ship_new_last_name = $_POST['co_last_name_new']; $ship_new_address = $_POST['co_street_new']; $ship_new_city = $_POST['co_city_new']; $ship_new_code = $_POST['co_code_new']; $ship_new_country = $_POST['co_country_new']; $ship_new_county = $_POST['co_state_county_new']; $ship_new_contact_number = $_POST['co_number_new']; // if checking title // if(isset($shipping_address_old)) { $final_ship_title = $_POST['co_title']; } else { $final_ship_title = $_POST['co_title_new']; } // ================= // // if checking first name // if(isset($shipping_address_old)) { $final_ship_first_name = $_POST['co_first_name']; } else { $final_ship_first_name = $_POST['co_first_name_new']; } // ================= // // if checking last name // if(isset($shipping_address_old)) { $final_ship_last_name = $_POST['co_last_name']; } else { $final_ship_last_name = $_POST['co_last_name_new']; } // ================= // // if checking address // if(isset($shipping_address_old)) { $final_ship_address = $_POST['co_street']; } else { $final_ship_address = $_POST['co_street_new']; } // ================= // // if checking address // if(isset($shipping_address_old)) { $final_ship_city = $_POST['co_city']; } else { $final_ship_city = $_POST['co_city_new']; } // ================= // // if checking address // if(isset($shipping_address_old)) { $final_ship_code = $_POST['co_code']; } else { $final_ship_code = $_POST['co_code_new']; } // ================= // // if checking address // if(isset($shipping_address_old)) { $final_ship_country = $_POST['co_country']; } else { $final_ship_country = $_POST['co_country_new']; } // ================= // // if checking address // if(isset($shipping_address_old)) { $final_ship_county_state = $_POST['co_state_county']; } else { $final_ship_county_state = $_POST['co_state_county_new']; } // ================= // // if checking address // if(isset($shipping_address_old)) { $final_ship_number = $_POST['co_number']; } else { $final_ship_number = $_POST['co_number_new']; } // ================= // // display block for the payment section // // The customers details form ======================================================= // print("<table width=\"80%\" border=\"0\" cellspacing=\"1\" cellpadding=\"5\">\n"); print("<tr>"); print("<th colspan=\"4\"><b>Below is your shipping details. [<a class=\"smart_links\" href=\"account.php\">Last Chance to Edit Your Address</a>]</b></th>"); print("</tr>"); print("<tr>"); print("<td class=\"td_style\" colspan=\"2\" align=\"left\">Title</td><td class=\"td_style\" align=\"left\"><b>$final_ship_title</b></td>"); print("</tr>\n"); print("<tr>\n"); print("<td class=\"td_style\" colspan=\"2\" align=\"left\">First Name</td><td class=\"td_style\" align=\"left\"><b>$final_ship_first_name</b></td>\n"); print("</tr>\n"); print("<tr>\n"); print("<td class=\"td_style\" colspan=\"2\" align=\"left\">Last Name</td><td class=\"td_style\" align=\"left\"><b>$final_ship_last_name</b></td>\n"); print("</tr>\n"); print("<tr>\n"); print("<td class=\"td_style\" colspan=\"2\" align=\"left\">Street Address</td><td class=\"td_style\" align=\"left\"><b>$final_ship_address</b></td>\n"); print("</tr>\n"); print("<tr>\n"); print("<td class=\"td_style\" colspan=\"2\" align=\"left\">City</td><td class=\"td_style\" align=\"left\"><b>$final_ship_city</b></td>\n"); print("</tr>\n"); print("<tr>\n"); print("<td class=\"td_style\" colspan=\"2\" align=\"left\">Zip / Postal Code</td><td class=\"td_style\" align=\"left\"><b>$final_ship_code</b></td>\n"); print("</tr>\n"); print("<tr>\n"); print("<td class=\"td_style\" colspan=\"2\" align=\"left\">Country</td><td class=\"td_style\" align=\"left\"><b>$final_ship_country</b></td>\n"); print("</tr>\n"); print("<tr>\n"); print("<td class=\"td_style\" colspan=\"2\" align=\"left\">State / County</td><td class=\"td_style\" align=\"left\"><b>$final_ship_county_state</b></td>\n"); print("</tr>\n"); print("<tr>\n"); print("<td class=\"td_style\" colspan=\"2\" align=\"left\">Contact Number</td><td class=\"td_style\" align=\"left\"><b>$final_ship_number</b></td>\n"); print("</tr>\n"); print("</table>\n"); print("<br />\n"); // ====================================================================================== // switch($payment_method) { case "pp"; ## MAYBE LATER ## break; case "cc"; print('<form action="https://select-test.worldpay.com/wcc/purchase" method="POST" id="world_pay_form">'); // hidden vars needed by world pay // print('<input type="hidden" name="testMode" value="100">'); print('<input type="hidden" name="instId" value="210905">'); print('<input type="hidden" name="cartId" value="abc123">'); print('<input type="hidden" name="currency" value="GBP">'); print("<table width=\"80%\" border=\"1\" bordercolor=\"#d9dce2\" cellspacing=\"0\" cellpadding=\"6\">"); print("<tr>\n"); print("<th>Preview</th><th>Product Name</th><th>Price</th><th>Quantity</th><th>Sum-Total</th>\n"); print("</tr>\n"); print("<tr>\n"); // here we get all the orders for the logged in user // $q_order = "SELECT `product_id`,`quantity`,`quantity_total` FROM `fcp_orders` WHERE `customer_id`='$var_loggedinuserid'"; $r_order = mysql_query($q_order); // next loop them out // while ($r_order) { // order vars // $cus_product_id = $order['product_id']; $cus_quantity = $order['quantity']; $cus_quantity_total = $order['quantity_total']; // products // $q_products = "SELECT `product_name`,`product_price`,`product_thumbnail` FROM `fcp_products` WHERE `id`='$cus_product_id'"; $r_products = mysql_query($q_products); $product = mysql_fetch_array($r_products); // more vars // $cus_product_name = $product['product_name']; $cus_product_price = $product['product_price']; $cus_product_thumb = $product['product_thumbnail']; print("<tr>\n"); print("<td class=\"td_style\" align=\"center\"><img src='products/thumbnails/$cus_product_thumb'></td>\n"); print("<td class=\"td_style\" align=\"center\"><a class=\"smart_links\" href=\"product-information.php?productid=$cus_product_id\">$cus_product_name</a> <input type=\"hidden\" name=\"item_name_$count\" value=\"$cus_product_name\"></td>\n"); print("<td class=\"td_style\" align=\"center\">£$cus_product_price <input type=\"hidden\" name=\"amount_$count\" value=\"$cus_product_price\"></td>\n"); print("<td class=\"td_style\" align=\"center\">$cus_quantity <input type=\"hidden\" name=\"quantity_$count\" value=\"$cus_quantity\"></td>\n"); print("<td class=\"td_style\" align=\"center\">£$cus_quantity_total</td>\n"); print("</tr>\n"); } print("</tr>"); print("<tr>"); print("<td colspan=\"5\" class=\"td_style\" align=\"center\"><input type=\"hidden\" name=\"amount\" value=\"$total_owed\"><input type='submit' name='submit' value='Authorize Payment...'></td>"); print("</tr>"); print("</table>"); print("</form>"); break; } // end switch // // ====================================================================================== // ?> time out part: <?php case "cc"; print('<form action="https://select-test.worldpay.com/wcc/purchase" method="POST" id="world_pay_form">'); // hidden vars needed by world pay // print('<input type="hidden" name="testMode" value="100">'); print('<input type="hidden" name="instId" value="210905">'); print('<input type="hidden" name="cartId" value="abc123">'); print('<input type="hidden" name="currency" value="GBP">'); print("<table width=\"80%\" border=\"1\" bordercolor=\"#d9dce2\" cellspacing=\"0\" cellpadding=\"6\">"); print("<tr>\n"); print("<th>Preview</th><th>Product Name</th><th>Price</th><th>Quantity</th><th>Sum-Total</th>\n"); print("</tr>\n"); print("<tr>\n"); // here we get all the orders for the logged in user // $q_order = "SELECT `product_id`,`quantity`,`quantity_total` FROM `fcp_orders` WHERE `customer_id`='$var_loggedinuserid'"; $r_order = mysql_query($q_order); // next loop them out // while ($r_order) { // order vars // $cus_product_id = $order['product_id']; $cus_quantity = $order['quantity']; $cus_quantity_total = $order['quantity_total']; // products // $q_products = "SELECT `product_name`,`product_price`,`product_thumbnail` FROM `fcp_products` WHERE `id`='$cus_product_id'"; $r_products = mysql_query($q_products); $product = mysql_fetch_array($r_products); // more vars // $cus_product_name = $product['product_name']; $cus_product_price = $product['product_price']; $cus_product_thumb = $product['product_thumbnail']; print("<tr>\n"); print("<td class=\"td_style\" align=\"center\"><img src='products/thumbnails/$cus_product_thumb'></td>\n"); print("<td class=\"td_style\" align=\"center\"><a class=\"smart_links\" href=\"product-information.php?productid=$cus_product_id\">$cus_product_name</a> <input type=\"hidden\" name=\"item_name_$count\" value=\"$cus_product_name\"></td>\n"); print("<td class=\"td_style\" align=\"center\">£$cus_product_price <input type=\"hidden\" name=\"amount_$count\" value=\"$cus_product_price\"></td>\n"); print("<td class=\"td_style\" align=\"center\">$cus_quantity <input type=\"hidden\" name=\"quantity_$count\" value=\"$cus_quantity\"></td>\n"); print("<td class=\"td_style\" align=\"center\">£$cus_quantity_total</td>\n"); print("</tr>\n"); } print("</tr>"); print("<tr>"); print("<td colspan=\"5\" class=\"td_style\" align=\"center\"><input type=\"hidden\" name=\"amount\" value=\"$total_owed\"><input type='submit' name='submit' value='Authorize Payment...'></td>"); print("</tr>"); print("</table>"); print("</form>"); break; ?> any ideas on what i could check at all? thanks guys Graham Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 24, 2008 Share Posted April 24, 2008 while ($order = mysql_fetch_array($r_order)) { Use that. =) Quote Link to comment Share on other sites More sharing options...
Zhadus Posted April 24, 2008 Share Posted April 24, 2008 What DarkWater stated should work for you, but additionally you should avoid outputting data while doing a MySQL query. I would suggest loading the data into an array first and then doing another loop to output the information. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 24, 2008 Share Posted April 24, 2008 The problem was that $r_order basically made it: while (true) { I THINK. I didn't test it, but that's my guess. Quote Link to comment Share on other sites More sharing options...
Zhadus Posted April 24, 2008 Share Posted April 24, 2008 The problem was that $r_order basically made it: while (true) { I THINK. I didn't test it, but that's my guess. You are correct. If it's an invalid query it returns false and would skip it, but because it's valid it returns the resource which technically would be true as well Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 24, 2008 Share Posted April 24, 2008 Yeah, that was my line of thought. xD Quote Link to comment Share on other sites More sharing options...
graham23s Posted April 24, 2008 Author Share Posted April 24, 2008 ocht lol so it was thanks guys lol Graham Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.