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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.