kclark Posted February 6, 2011 Share Posted February 6, 2011 I have a code that I am using to update multiple products at one time instead of one at a time. It works great except that my processing page is not updating the very last product. My process page is receiving all of my products as I know how many products that I am updating and I have my process page tell me how many products are updated as well as listing the name of each product updated. It is always the last product that is not updated. Here is my process update code. <?php $size = count($_POST['casketid']); //$size = 306; $i = 1; while ($i < $size) { $product=$_POST['productid'][$i];//getting case # $price=$_POST['price'][$i]; $model=$_POST['model'][$i]; $active=$_POST['active'][$i]; //Getting pricerange if(($price > "0") && ($price <= "1000.00")) $pricerange = "1"; elseif(($price >= "1001.00") && ($price <= "1500.00")) $pricerange = "2"; elseif(($price >= "1501.00") && ($price <= "2000.00")) $pricerange = "3"; elseif(($price <= "2001.00") && ($price <= "2500.00")) $pricerange = "4"; elseif(($price <= "2501.00") && ($price <= "3000.00")) $pricerange = "5"; elseif(($price >= "3001.00") && ($price <= "3500.00")) $pricerange = "6"; elseif(($price >= "3501.00") && ($price <= "4000.00")) $pricerange = "7"; elseif(($price >= "4001.00") && ($price <= "4500.00")) $pricerange = "8"; elseif(($price >= "4501.00") && ($price <= "4500.00")) $pricerange = "9"; elseif($price >= "5001.00") $pricerange = "10"; $query = "UPDATE products SET price='$price', pricerange='$pricerange', active='$active' WHERE productid='$product'"; mysql_query($query) or die ("Error in query: $query"); echo "$model = $price & active = $active</em><br />$size<br />"; ++$i; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/226905-loop-thru-multiple-update/ Share on other sites More sharing options...
PaulRyan Posted February 6, 2011 Share Posted February 6, 2011 Try changing this line... while ($i < $size) { To this... while ($i <= $size) { Tell what happens buddy Regards, PaulRyan. Quote Link to comment https://forums.phpfreaks.com/topic/226905-loop-thru-multiple-update/#findComment-1170778 Share on other sites More sharing options...
kclark Posted February 6, 2011 Author Share Posted February 6, 2011 thanks a bunch that did it Quote Link to comment https://forums.phpfreaks.com/topic/226905-loop-thru-multiple-update/#findComment-1170782 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.