hi all
i m trying to update multiple rows which contain product price.
when i update the price of last product to 450.00 then all product prices get updated as 450.00
when i update the price of 1st or second product then no product price gets updated.
This is update script
if(isset($_REQUEST['submit'])) {
$msg = (string) '';
$prid=array();
$new_price=$_REQUEST['new_price'];
$prid=$_REQUEST['prid'];
$count=count($prid);
for($i=0;$i<$count-1;$i++) {
$del_id = $prid[$i];
$qry2 = "update product_table set price='$new_price' where product_id =$del_id";
echo $qry2;
$result2 = mysql_query($qry2);
if($result2 && mysql_affected_rows() > 0) {
$msg .= "Product ( ".$del_id." ) updated Successfully<br />";
}
else {
$msg .= "Error updating product $del_id<br />";
} } }
This is display script
<?php
$qry="select * from product_table where dealer_id=$dealer_id and sub_catg='$sub_catg' order by product_id asc";
$result = mysql_query($qry);
if(mysql_num_rows($result)>0)
{
while($row=mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>". "<input type='hidden' name='prid[]' id='prid[]' value=". $row['product_id']. ">"."</td>";
echo "<td valign=top>". $row['product_id'] . "</td>";
echo "<td valign=top>". $row['product_name'] . "</td>";
echo "<td valign=top>". $row['price'] . "</td>";
echo "<td valign=top>"."<input type='text' name='new_price' id='new_price'>" . "</td>";
echo "</tr>";
}
echo "<td valign='top' colspan='9'><input name='submit' type='submit' value='Update Prices' />";
echo "<input type='hidden' name='prid[]' value=".$row2['product_id']." />";
echo "</td>";
}
?>
vineet