Jump to content

loop thru multiple update


kclark

Recommended Posts

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;
}


?>

Link to comment
https://forums.phpfreaks.com/topic/226905-loop-thru-multiple-update/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.