cybercrawler Posted March 6, 2012 Share Posted March 6, 2012 I have created a form, that contains multiple text fields. When the user clicks on the Submit button, the form data should be populated in MySQL, I have programmed it in a way, that it works well, but the problem is, Since it contains so many text fields that collects the Manufacturer, Brand and so on repeatedly, I have created multiple queries to populate the DB. Here is the code, <?php include("connect.php"); if (isset($_POST['confirm_order'])) { $o_manufacturer = trim(@$_POST['o_manufacturer']); $o_brand = trim(@$_POST['o_brand']); $o_type = trim(@$_POST['o_type']); $o_exp_date = trim(@$_POST['o_exp_date']); $o_qty = trim(@$_POST['o_qty']); $o_unit = trim(@$_POST['o_unit']); $o_unit_price = trim(@$_POST['o_unit_price']); $o_package = trim(@$_POST['o_package']); $o_package_price = trim(@$_POST['o_package_price']); $o_selling_price_perUnit = trim(@$_POST['o_selling_price_perUnit']); $query = "INSERT INTO order_entry (o_sno, o_manufacturer, o_brand, o_type, o_exp_date, o_qty, o_unit, o_unit_price, o_package, o_package_price, o_selling_price_perUnit) VALUES ('', '$o_manufacturer', '$o_brand', '$o_type', '$o_exp_date', '$o_qty', '$o_unit', '$o_unit_price', '$o_package', '$o_package_price', '$o_selling_price_perUnit')"; $results = mysql_query($query); if ($results) { echo '<center><p class=small>Order updation successful, Click on LIST ORDERS button below to view the order entry.</p><br></center>'; echo '<center><a href="List_Orders.php" class="myButton">List Orders</a></center>'; } // Second Row Insertion if(!empty($_POST['o_manufacturer1'])) { $query = "INSERT INTO order_entry (o_sno, o_manufacturer, o_brand, o_type, o_exp_date, o_qty, o_unit, o_unit_price, o_package, o_package_price, o_selling_price_perUnit) VALUES ('', '".$_POST['o_manufacturer1']."' , '".$_POST['o_brand1']."' , '".$_POST['o_type1']."' , '".$_POST['o_exp_date1']."' , '".$_POST['o_qty1']."' , '".$_POST['o_unit1']."' , '".$_POST['o_unit_price1']."' , '".$_POST['o_package1']."' , '".$_POST['o_package_price1']."', '".$_POST['o_selling_price_perUnit1']."' )"; $results = mysql_query($query); } // Third Row Insertion if(!empty($_POST['o_manufacturer2'])) { $query = "INSERT INTO order_entry (o_sno, o_manufacturer, o_brand, o_type, o_exp_date, o_qty, o_unit, o_unit_price, o_package, o_package_price, o_selling_price_perUnit) VALUES ('', '".$_POST['o_manufacturer2']."' , '".$_POST['o_brand2']."' , '".$_POST['o_type2']."' , '".$_POST['o_exp_date2']."' , '".$_POST['o_qty2']."' , '".$_POST['o_unit2']."' , '".$_POST['o_unit_price2']."' , '".$_POST['o_package2']."' , '".$_POST['o_package_price2']."', '".$_POST['o_selling_price_perUnit2']."' )"; $results = mysql_query($query); } // Fourth Row Insertion if(!empty($_POST['o_manufacturer3'])) { $query = "INSERT INTO order_entry (o_sno, o_manufacturer, o_brand, o_type, o_exp_date, o_qty, o_unit, o_unit_price, o_package, o_package_price, o_selling_price_perUnit) VALUES ('', '".$_POST['o_manufacturer3']."' , '".$_POST['o_brand3']."' , '".$_POST['o_type3']."' , '".$_POST['o_exp_date3']."' , '".$_POST['o_qty3']."' , '".$_POST['o_unit3']."' , '".$_POST['o_unit_price3']."' , '".$_POST['o_package3']."' , '".$_POST['o_package_price3']."', '".$_POST['o_selling_price_perUnit3']."' )"; $results = mysql_query($query); } // Fifth Row Insertion if(!empty($_POST['o_manufacturer4'])) { $query = "INSERT INTO order_entry (o_sno, o_manufacturer, o_brand, o_type, o_exp_date, o_qty, o_unit, o_unit_price, o_package, o_package_price, o_selling_price_perUnit) VALUES ('', '".$_POST['o_manufacturer4']."' , '".$_POST['o_brand4']."' , '".$_POST['o_type4']."' , '".$_POST['o_exp_date4']."' , '".$_POST['o_qty4']."' , '".$_POST['o_unit4']."' , '".$_POST['o_unit_price4']."' , '".$_POST['o_package4']."' , '".$_POST['o_package_price4']."', '".$_POST['o_selling_price_perUnit4']."' )"; $results = mysql_query($query); } mysql_close(); } ?> Instead of posting the 'o_manufacturer ' value multiple times 'o_manufacturer1', 'o_manufacturer2', 'o_manufacturer3' and 'o_manufacturer4' I m looking for a code, that uses for loop or any other alternative ways that optimizes the code and works the proper way... NOTE : The file that i have attached is working 100% perfect, but I am looking for code optimization. Looking for help from experts.. Thanks a lot in advance... 17722_.php Quote Link to comment https://forums.phpfreaks.com/topic/258403-problem-in-optimizing-the-code/ Share on other sites More sharing options...
AbraCadaver Posted March 6, 2012 Share Posted March 6, 2012 Something like this: $cols = "`" . implode("`,`", array_keys($_POST)) . "`"; $data = "'" . implode("','", array_map("mysql_real_escape_string", $_POST)) . "'"; $sql = "INSERT INTO $table ($cols) VALUES ($vals)"; Quote Link to comment https://forums.phpfreaks.com/topic/258403-problem-in-optimizing-the-code/#findComment-1324569 Share on other sites More sharing options...
cybercrawler Posted March 8, 2012 Author Share Posted March 8, 2012 Thanx a lot for your response AbraCadaver...... Lemme check whether it workz 5n... Quote Link to comment https://forums.phpfreaks.com/topic/258403-problem-in-optimizing-the-code/#findComment-1325074 Share on other sites More sharing options...
cybercrawler Posted March 8, 2012 Author Share Posted March 8, 2012 I tried modifying my code, using the Implode function as given.. but now nothing is getting populated in the DB. Herewith I Have included the code here... <html> <head><title>New Order</title> <link href="style.css" rel="stylesheet" type="text/css" /> <!-- Form Validation --> <script type="text/javascript"> function validateForm() { var manu=document.forms["order_details"]["o_manufacturer"].value; if (manu==null || manu=="") { alert("Manufacturer name must be filled"); order_details.o_manufacturer.focus(); return false; } var brand=document.forms["order_details"]["o_brand"].value; if (brand==null || brand=="") { alert("Brand Name must be filled"); order_details.o_brand.focus(); return false; } var exp_date=document.forms["order_details"]["o_exp_date"].value; if (exp_date==null || exp_date=="") { alert("Expiry Date must be filled"); order_details.o_exp_date.focus(); return false; } var qty=document.forms["order_details"]["o_qty"].value; if (qty==null || qty=="") { alert("Quantity must be filled"); order_details.o_qty.focus(); return false; } else { if (isNaN(order_details.o_qty.value)) { alert("Only Numbers are allowed in Qty Field"); order_details.o_qty.value=''; order_details.o_qty.focus(); return false; } } var unit=document.forms["order_details"]["o_unit"].value; if (unit==null || unit=="") { alert("Unit must be filled"); order_details.o_unit.focus(); return false; } else { if (isNaN(order_details.o_unit.value)) { alert("Only Numbers are allowed in unit Field"); order_details.o_unit.value=''; order_details.o_unit.focus(); return false; } } var unit=document.forms["order_details"]["o_unit_price"].value; if (unit==null || unit=="") { alert("Unit must be filled"); order_details.o_unit_price.focus(); return false; } else { if (isNaN(order_details.o_unit_price.value)) { alert("Only Numbers are allowed in unit Field"); order_details.o_unit_price.value=''; order_details.o_unit_price.focus(); return false; } } var unit=document.forms["order_details"]["o_package"].value; if (unit==null || unit=="") { alert("Package size must be filled"); order_details.o_package.focus(); return false; } else { if (isNaN(order_details.o_package.value)) { alert("Only Numbers are allowed in Package Field"); order_details.o_package.value=''; order_details.o_package.focus(); return false; } } var unit=document.forms["order_details"]["o_package_price"].value; if (unit==null || unit=="") { alert("Package size must be filled"); order_details.o_package_price.focus(); return false; } else { if (isNaN(order_details.o_package_price.value)) { alert("Only Numbers are allowed in Package Field"); order_details.o_package_price.value=''; order_details.o_package_price.focus(); return false; } } var unit=document.forms["order_details"]["o_selling_price_perUnit"].value; if (unit==null || unit=="") { alert("Package size must be filled"); order_details.o_selling_price_perUnit.focus(); return false; } else { if (isNaN(order_details.o_selling_price_perUnit.value)) { alert("Only Numbers are allowed in Package Field"); order_details.o_selling_price_perUnit.value=''; order_details.o_selling_price_perUnit.focus(); return false; } } } </script> </head> <body> <!-- Second Legend --> <center> <form name="order_entry" class="style1 style2" > <fieldset class=extend> <legend>Order Entry</legend> <table border=0 width=700 style='table-layout:fixed'> <!-- order_details Name --> <tr> <td colspan=4 align="center"> <p class="small"><font color="#ffffff"> </font></p> </td> </tr> <!-- Order Number & Order Date --> <tr> <td colspan=2 > <p class="small"><label>ORDER NO : </label></p> </td> <td colspan=2 > <p class="small" align="center"><label>ORDER DATE : </label></p> </td> </tr> <!-- Order Reference --> <tr> <td colspan=2 > <p class="small"><label>ORDER REFERENCE : </label></p> </td> </tr> </table> </form> <form name='order_details' action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" onsubmit="return validateForm()"> <table border=0 width=800 style='table-layout:fixed'> <col width=10> <col width=65> <col width=50> <col width=45> <col width=35> <col width=20> <col width=20> <col width=30> <col width=30> <col width=30> <col width=35> <tr> <th valign="top"> <p class="small"><label>S.No</label></p> </th> <th valign="top"> <p class="small"><label>Manufacturer</label></p> </th> <th valign="top"> <p class="small"><label>Brand</label></p> </th> <th valign="top"> <p class="small"><label>Type</label></p> </th> <th valign="top"> <p class="small"><label>Exp.Date</label></p> </th> <th valign="top"> <p class="small"><label>Qty</label></p> </th> <th valign="top"> <p class="small"><label>Unit</label></p> </th> <th valign="top"> <p class="small"><label>U.Price</label></p> </th> <th valign="top"> <p class="small"><label>Package</label></p> </th> <th valign="top"> <p class="small"><label>P.Price</label></p> </th> <th valign="top"> <p class="small"><label>S.Price/Unit</label></p> </th> </tr> <!-- First Row : START --> <tr> <td valign="top"> <p class="small"><label> 1 </label></p> </td> <td valign="top"> <p class="small"><INPUT type="text" name="o_manufacturer" maxlength="40" size=20></input></p> </td> <td valign="top"> <p class="small"><INPUT type="text" name="o_brand" maxlength="40" size=14></p> </td> <td valign="top"> <p class="small"> <select name="o_type"> <option>None</option> <option>Capsule</option> <option>Drops</option> <option>Gel</option> <option>Infusion</option> <option>Injection</option> <option>Kit</option> <option>Mouth Wash</option> <option>Ointment</option> <option>Powder</option> <option>Tablet</option> <option>Suspension</option> <option>Syrup</option> <option>Others</option> </select> </td> </p> <td valign="top"> <p class="small"><INPUT type="text" name="o_exp_date" maxlength="10" size=10></p> </td> <td valign="top"> <p class="small"><INPUT type="text" name="o_qty" maxlength="6" size=4></p> </td> <td valign="top"> <p class="small"><INPUT type="text" name="o_unit" maxlength="10" size=4></p> </td> <td valign="top"> <p class="small"><INPUT type="text" name="o_unit_price" maxlength="10" size=8></p> </td> <td valign="top"> <p class="small"><INPUT type="text" name="o_package" maxlength="10" size=8></p> </td> <td valign="top"> <p class="small"><INPUT type="text" name="o_package_price" maxlength="10" size=8></p> </td> <td valign="top"> <p class="small"><INPUT type="text" name="o_selling_price_perUnit" maxlength="10" size=10></p> </td> </tr> <!-- First Row:END --> <!-- Second Row:Start --> <tr> <td valign="top"> <p class="small"><label> 2 </label></p> </td> <td valign="top"> <p class="small"><INPUT type="text" name="o_manufacturer1" maxlength="40" size=20></input></p> </td> <td valign="top"> <p class="small"><INPUT type="text" name="o_brand1" maxlength="40" size=14></p> </td> <td valign="top"> <p class="small"> <select name="o_type1"> <option>None</option> <option>Capsule</option> <option>Drops</option> <option>Gel</option> <option>Infusion</option> <option>Injection</option> <option>Kit</option> <option>Mouth Wash</option> <option>Ointment</option> <option>Powder</option> <option>Tablet</option> <option>Suspension</option> <option>Syrup</option> <option>Others</option> </select> </td> </p> <td valign="top"> <p class="small"><INPUT type="text" name="o_exp_date1" maxlength="10" size=10></p> </td> <td valign="top"> <p class="small"><INPUT type="text" name="o_qty1" maxlength="6" size=4></p> </td> <td valign="top"> <p class="small"><INPUT type="text" name="o_unit1" maxlength="10" size=4></p> </td> <td valign="top"> <p class="small"><INPUT type="text" name="o_unit_price1" maxlength="10" size=8></p> </td> <td valign="top"> <p class="small"><INPUT type="text" name="o_package1" maxlength="10" size=8></p> </td> <td valign="top"> <p class="small"><INPUT type="text" name="o_package_price1" maxlength="10" size=8></p> </td> <td valign="top"> <p class="small"><INPUT type="text" name="o_selling_price_perUnit1" maxlength="10" size=10></p> </td> </tr> <!-- Second Row:END --> <!-- Third Row:Start --> <tr> <td valign="top"> <p class="small"><label> 3 </label></p> </td> <td valign="top"> <p class="small"><INPUT type="text" name="o_manufacturer2" maxlength="40" size=20></input></p> </td> <td valign="top"> <p class="small"><INPUT type="text" name="o_brand2" maxlength="40" size=14></p> </td> <td valign="top"> <p class="small"> <select name="o_type2"> <option>None</option> <option>Capsule</option> <option>Drops</option> <option>Gel</option> <option>Infusion</option> <option>Injection</option> <option>Kit</option> <option>Mouth Wash</option> <option>Ointment</option> <option>Powder</option> <option>Tablet</option> <option>Suspension</option> <option>Syrup</option> <option>Others</option> </select> </td> </p> <td valign="top"> <p class="small"><INPUT type="text" name="o_exp_date2" maxlength="10" size=10></p> </td> <td valign="top"> <p class="small"><INPUT type="text" name="o_qty2" maxlength="6" size=4></p> </td> <td valign="top"> <p class="small"><INPUT type="text" name="o_unit2" maxlength="10" size=4></p> </td> <td valign="top"> <p class="small"><INPUT type="text" name="o_unit_price2" maxlength="10" size=8></p> </td> <td valign="top"> <p class="small"><INPUT type="text" name="o_package2" maxlength="10" size=8></p> </td> <td valign="top"> <p class="small"><INPUT type="text" name="o_package_price2" maxlength="10" size=8></p> </td> <td valign="top"> <p class="small"><INPUT type="text" name="o_selling_price_perUnit2" maxlength="10" size=10></p> </td> </tr> <!-- Third Row:END --> <!-- Fourth Row:Start --> <tr> <td valign="top"> <p class="small"><label> 4 </label></p> </td> <td valign="top"> <p class="small"><INPUT type="text" name="o_manufacturer3" maxlength="40" size=20></input></p> </td> <td valign="top"> <p class="small"><INPUT type="text" name="o_brand3" maxlength="40" size=14></p> </td> <td valign="top"> <p class="small"> <select name="o_type3"> <option>None</option> <option>Capsule</option> <option>Drops</option> <option>Gel</option> <option>Infusion</option> <option>Injection</option> <option>Kit</option> <option>Mouth Wash</option> <option>Ointment</option> <option>Powder</option> <option>Tablet</option> <option>Suspension</option> <option>Syrup</option> <option>Others</option> </select> </td> </p> <td valign="top"> <p class="small"><INPUT type="text" name="o_exp_date3" maxlength="10" size=10></p> </td> <td valign="top"> <p class="small"><INPUT type="text" name="o_qty3" maxlength="6" size=4></p> </td> <td valign="top"> <p class="small"><INPUT type="text" name="o_unit3" maxlength="10" size=4></p> </td> <td valign="top"> <p class="small"><INPUT type="text" name="o_unit_price3" maxlength="10" size=8></p> </td> <td valign="top"> <p class="small"><INPUT type="text" name="o_package3" maxlength="10" size=8></p> </td> <td valign="top"> <p class="small"><INPUT type="text" name="o_package_price3" maxlength="10" size=8></p> </td> <td valign="top"> <p class="small"><INPUT type="text" name="o_selling_price_perUnit3" maxlength="10" size=10></p> </td> </tr> <tr> <!-- Fourth Row:END --> <!-- Fifth Row:Start --> <tr> <td valign="top"> <p class="small"><label> 5 </label></p> </td> <td valign="top"> <p class="small"><INPUT type="text" name="o_manufacturer4" maxlength="40" size=20></input></p> </td> <td valign="top"> <p class="small"><INPUT type="text" name="o_brand4" maxlength="40" size=14></p> </td> <td valign="top"> <p class="small"> <select name="o_type4"> <option>None</option> <option>Capsule</option> <option>Drops</option> <option>Gel</option> <option>Infusion</option> <option>Injection</option> <option>Kit</option> <option>Mouth Wash</option> <option>Ointment</option> <option>Powder</option> <option>Tablet</option> <option>Suspension</option> <option>Syrup</option> <option>Others</option> </select> </td> </p> <td valign="top"> <p class="small"><INPUT type="text" name="o_exp_date4" maxlength="10" size=10></p> </td> <td valign="top"> <p class="small"><INPUT type="text" name="o_qty4" maxlength="6" size=4></p> </td> <td valign="top"> <p class="small"><INPUT type="text" name="o_unit4" maxlength="10" size=4></p> </td> <td valign="top"> <p class="small"><INPUT type="text" name="o_unit_price4" maxlength="10" size=8></p> </td> <td valign="top"> <p class="small"><INPUT type="text" name="o_package4" maxlength="10" size=8></p> </td> <td valign="top"> <p class="small"><INPUT type="text" name="o_package_price4" maxlength="10" size=8></p> </td> <td valign="top"> <p class="small"><INPUT type="text" name="o_selling_price_perUnit4" maxlength="10" size=10></p> </td> </tr> <center> <td colspan=5><center><input type="submit" name="confirm_order" value=" Confirm Order " class='myButton'></input></center></td> <td colspan=5><center><input type="reset" name="cancel_order" value=" Cancel Order " class='myButton'></input></center></td> </center> </tr> <!-- FIfth Row:END --> </table> </form> <?php include("connect.php"); $cols = "`" . implode("`,`", array_keys($_POST)) . "`"; $data = "'" . implode("','", array_map("mysql_real_escape_string", $_POST)) . "'"; $sql = "INSERT INTO order_entry ($cols) VALUES ($data)"; if ($sql) { echo '<center><p class=small>Order updation successful, Click on LIST ORDERS button below to view the order entry.</p><br></center>'; echo '<center><a href="List_Orders.php" class="myButton">List Orders</a></center>'; } mysql_close(); ?> </body> </html> What's wrong in this code ?? Quote Link to comment https://forums.phpfreaks.com/topic/258403-problem-in-optimizing-the-code/#findComment-1325096 Share on other sites More sharing options...
PFMaBiSmAd Posted March 8, 2012 Share Posted March 8, 2012 You need to use arrays for your form field names - http://us2.php.net/manual/en/faq.html.php#faq.html.arrays You would also want to dynamically produce the repeating regions of the form using php code so that you keep it simple so that making any changes to the number of repeating regions or to the actual html would be done in only one place, not four different places. Then, you can simply use php array functions in your form processing code. Edit: I also notice that you have put the php form processing logic in the same file with the form, but you have not logic to distuniguish if the form was submitted before using the data from the form. If your form processing code is actually in the same file with the form, you would need to add logic so that the form procesing code is only execuited after the form has been submitted (otherwise you will be inserting empty values into your database table.) Also, your javascript validation appears (I didn't read it completely) to only validate the first set of data and you always need to validate all external data on the server after it has been submitted. Quote Link to comment https://forums.phpfreaks.com/topic/258403-problem-in-optimizing-the-code/#findComment-1325099 Share on other sites More sharing options...
PFMaBiSmAd Posted March 8, 2012 Share Posted March 8, 2012 You can rewrite that particular part of your <form ...> ... </form> as - <?php $num_regions = 5; // number of repeat regions in the form ?> <form name='order_details' action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" onsubmit="return validateForm()"> <table border=0 width=800 style='table-layout:fixed'> <col width=10> <col width=65> <col width=50> <col width=45> <col width=35> <col width=20> <col width=20> <col width=30> <col width=30> <col width=30> <col width=35> <tr> <th valign="top"><p class="small"><label>S.No</label></p></th> <th valign="top"><p class="small"><label>Manufacturer</label></p></th> <th valign="top"><p class="small"><label>Brand</label></p></th> <th valign="top"><p class="small"><label>Type</label></p></th> <th valign="top"><p class="small"><label>Exp.Date</label></p></th> <th valign="top"><p class="small"><label>Qty</label></p></th> <th valign="top"><p class="small"><label>Unit</label></p></th> <th valign="top"><p class="small"><label>U.Price</label></p></th> <th valign="top"><p class="small"><label>Package</label></p></th> <th valign="top"><p class="small"><label>P.Price</label></p></th> <th valign="top"><p class="small"><label>S.Price/Unit</label></p></th> </tr> <?php for($x=1;$x <= $num_regions;$x++){ echo <<<EOT <tr> <td valign="top"><p class="small"><label> $x </label></p></td> <td valign="top"><p class="small"><INPUT type="text" name="o_manufacturer[$x]" maxlength="40" size=20></input></p></td> <td valign="top"><p class="small"><INPUT type="text" name="o_brand[$x]" maxlength="40" size=14></p></td> <td valign="top"><p class="small"><select name="o_type[$x]"> <option>None</option> <option>Capsule</option> <option>Drops</option> <option>Gel</option> <option>Infusion</option> <option>Injection</option> <option>Kit</option> <option>Mouth Wash</option> <option>Ointment</option> <option>Powder</option> <option>Tablet</option> <option>Suspension</option> <option>Syrup</option> <option>Others</option> </select></p></td> <td valign="top"><p class="small"><INPUT type="text" name="o_exp_date[$x]" maxlength="10" size=10></p></td> <td valign="top"><p class="small"><INPUT type="text" name="o_qty[$x]" maxlength="6" size=4></p></td> <td valign="top"><p class="small"><INPUT type="text" name="o_unit[$x]" maxlength="10" size=4></p></td> <td valign="top"><p class="small"><INPUT type="text" name="o_unit_price[$x]" maxlength="10" size=8></p></td> <td valign="top"><p class="small"><INPUT type="text" name="o_package[$x]" maxlength="10" size=8></p></td> <td valign="top"><p class="small"><INPUT type="text" name="o_package_price[$x]" maxlength="10" size=8></p></td> <td valign="top"><p class="small"><INPUT type="text" name="o_selling_price_perUnit[$x]" maxlength="10" size=10></p></td> </tr> EOT; } ?> <tr> <center> <td colspan=5><center><input type="submit" name="confirm_order" value=" Confirm Order " class='myButton'></input></center></td> <td colspan=5><center><input type="reset" name="cancel_order" value=" Cancel Order " class='myButton'></input></center></td> </center> </tr> </table> </form> When the form is submitted, the data will look like - Array ( [o_manufacturer] => Array ( [1] => [2] => [3] => [4] => [5] => ) [o_brand] => Array ( [1] => [2] => [3] => [4] => [5] => ) [o_type] => Array ( [1] => None [2] => None [3] => None [4] => None [5] => None ) [o_exp_date] => Array ( [1] => [2] => [3] => [4] => [5] => ) [o_qty] => Array ( [1] => [2] => [3] => [4] => [5] => ) [o_unit] => Array ( [1] => [2] => [3] => [4] => [5] => ) [o_unit_price] => Array ( [1] => [2] => [3] => [4] => [5] => ) [o_package] => Array ( [1] => [2] => [3] => [4] => [5] => ) [o_package_price] => Array ( [1] => [2] => [3] => [4] => [5] => ) [o_selling_price_perUnit] => Array ( [1] => [2] => [3] => [4] => [5] => ) [confirm_order] => Confirm Order ) You can then simply loop over one of the sub-arrays (i.e. $_POST['o_manufacturer']), getting the key and the value, then use that key to access the corresponding values from the other sub-arrays. Quote Link to comment https://forums.phpfreaks.com/topic/258403-problem-in-optimizing-the-code/#findComment-1325112 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.