|
norwichdesign -> MySql mulitple row PHP update (11/17/2005 1:56:10)
|
Hi all, I'm creating an update page that will update all the rows in a mysql db. At the moment it only updates the last row of the table. Any help is greatly received. Code: if (isset($_POST['submit'])) { for ($i=0($_POST["id"]); $i++) { $theid = $_POST["id"][$i]; $qry = mysql_query("UPDATE products SET products_kelkoo_date = '$_REQUEST[products_kelkoo_date]', products_kelkoo_price = '$_REQUEST[products_kelkoo_price]', products_price = '$_REQUEST[products_price]', products_best_date = '$_REQUEST[products_best_date]', products_best_price = '$_REQUEST[products_best_price]', products_best_name = '$_REQUEST[products_best_name]', products_notes = '$_REQUEST[products_notes]' WHERE products_id = $theid"); mysql_query($qry); } } else { // read data from database $result = mysql_query("select * from products order by products_model limit $rows") or die ("Could not read data because ".mysql_error()); // print the data in a table if (mysql_num_rows($result)) { print "<div id=Main>"; print "<table cellpadding=2 cellspacing=0 border=1 width=\"1032\" bgcolor=#FFFBF0 style=border-color:#000066>\n"; print "<tr class=style4> <td width=27 bgcolor=#3399FF>ID</td> <td width=117 bgcolor=#3399FF>Make</td> <td width=128 bgcolor=#3399FF>Model</td> <td width=74 bgcolor=#3399FF>Kelkoo Price as of*</td> <td width=74 bgcolor=#3399FF>Kelkoo Lowest Price</td> <td width=55 bgcolor=#3399FF>Sell Price Incl VAT</td> <td width=55 bgcolor=#3399FF>Special Price</td> <td width=55 bgcolor=#3399FF>Kelkoo Price Diff</td> <td width=74 bgcolor=#3399FF>Sell Price Ex VAT</td> <td width=74 bgcolor=#3399FF>Buy Price as of*</td> <td width=74 bgcolor=#3399FF>Best Buy Price</td> <td width=85 bgcolor=#3399FF>Best Buy Company</td> <td width=165 bgcolor=#3399FF>Product Notes</td> </tr>"; while ($qry = mysql_fetch_array($result)) { $id=$qry[manufacturers_id]; $manufactdetails = mysql_query("SELECT manufacturers_name FROM manufacturers WHERE manufacturers_id=$id"); $manufact = mysql_fetch_array($manufactdetails); $manufacturers_name = $manufact[manufacturers_name]; $specialdetails = mysql_query("SELECT specials_new_products_price FROM specials WHERE products_id=$qry[products_id]"); $special = mysql_fetch_array($specialdetails); $specials_price = $special[specials_new_products_price]; // define what % vat is $vat = 17.5; // work out the amount of vat $price_with_vat = $qry[products_price] + ($vat*($qry[products_price]/100)); // Kelkoo difference sum $products_diff = ($qry[products_kelkoo_price] - $price_with_vat); // strings used in decimal point routine $vatprice = $price_with_vat; $price = $qry[products_price]; $numberkelkoo = $qry[products_kelkoo_price]; // Kelkoo difference to two decimal places $kelkoo_diff = number_format($products_diff, 2, '.', ''); // VAT price to two decimal places $products_price = number_format($price, 2, '.', ''); // Kelkoo price to two decimal places $kelkooprice = number_format($numberkelkoo, 2, '.', ''); // VAT price to two decimal places $products_vatprice = number_format($vatprice, 2, '.', ''); $specials_pricedec = number_format($specials_price, 2, '.', ''); // Display results print "<form name=opscreen method=post action=$_SERVER[PHP_SELF]>"; print "<tr class=style3> <td>$qry[products_id] <input name=id type=hidden value=$qry[products_id]></td> <td>$manufacturers_name </td> <td>$qry[products_model] </td> <td><input name=products_kelkoo_date type=text value= $qry[products_kelkoo_date] size=6 ></td> <td><input name=products_kelkoo_price type=text value= $kelkooprice size=6 ></td> <td>$products_vatprice </td> <td>$specials_pricedec </td> <td>$kelkoo_diff </td> <td><input name=products_price type=text value= $products_price size=5 ></td> <td><input name=products_best_date type=text value= $qry[products_best_date] size=5 ></td> <td><input name=products_best_price type=text value= $qry[products_best_price] size=5 ></td> <td><input name=products_best_name type=text value= $qry[products_best_name] size=6 ></td> <td><textarea rows=6 name=products_notes cols=12 >$qry[products_notes] </textarea></td>"; print "</td></tr>\n"; } print "</table></div>\n"; print "<input type=submit name=submit value=Update />"; print "</form>"; } } ?>
|
|
|
|