Dr1234 Posted April 11, 2012 Share Posted April 11, 2012 I am building a web price updates page for an e-commerce website, and would like to create a form where I can update products within the product group selected(via a drop down menu), by any percentage that is input by the user. There are 200 different product groups all containing a list of products that are stored within a database that is already connected to the webpage and displays a list of products, web price etc. I would like to be able to select a particular group from the drop down menu, then apply the percentage increase, that the user has input into the form through the text box, to the group of products selected. Hope this makes sense any help would be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
Dr1234 Posted April 11, 2012 Author Share Posted April 11, 2012 I have now got slightly further with this and have created an update form for this. The update form currently ouputs the new web price as a 40% increase as I have set it to do this. I would like a way to have a value input by the user (as the percentage increase) in place of the calculation for 40% percent increase so that it can be any number from the text box. if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) { $updateSQL = sprintf("UPDATE ProductsUpdated SET Web_Price=round((Web_Price)*1.40,2) // This is where I need my calculation for any percentage increase WHERE SageGroup='$sgroup'", GetSQLValueString($_POST['Web_Price'], "text"), GetSQLValueString($_POST['SageGroup'], "text")); Quote Link to comment Share on other sites More sharing options...
kicken Posted April 11, 2012 Share Posted April 11, 2012 Take whatever number they enter into the field, verify it is a number, and then convert it to a decimal percentage. For example: <?php $currentPrice = 54.99; if (isset($_POST['percent'])){ if (ctype_digit($_POST['percent'])){ $percent = intval($_POST['percent']); $percent /= 100; // Convert it from say 40 to 0.40 if ($_POST['type']=='+'){ $percent += 1; } else { $percent = 1 - $percent; } //Now $percent will be say 1.40 if an increase or .60 if a decrease //Just multiply it by the current price. echo $currentPrice * $percent; } } ?> <form action="" method="post"> Enter percent: <input type="text" name="percent">% Type: <select name="type"><option value="+">Increase</option><option value="-">decrease</option></select> </form> 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.