if(isset($_POST["update_invoice"]))
{

$order_item_hc = 0;


  $order_id = $_POST["order_id"];

  for($count=0; $count<$_POST["total_item"]; $count++)
  {
    $statement = $connect->prepare("
      update tbl_order_item 
      SET 
	  order_item_hsncode		=	:order_item_hsncode, 
	  order_item_name			=	:order_item_name,
	  order_item_quantity		=	:order_item_quantity,
	  order_item_price			=	:order_item_price,
	  order_item_actual_amount	=	:order_item_actual_amount
      WHERE order_id = :order_id 
    ");
    $statement->execute(
      array(
        ':order_id'                 =>  $order_id,
		':order_item_hsncode'       =>  trim($_POST["order_item_hsncode"][$count]),
        ':order_item_name'          =>  trim($_POST["order_item_name"][$count]),
        ':order_item_quantity'      =>  trim($_POST["order_item_quantity"][$count]),
        ':order_item_price'         =>  trim($_POST["order_item_price"][$count]),
        ':order_item_actual_amount' =>  trim($_POST["order_item_actual_amount"][$count])            
      )
    );
  }

    What does "is updating the last row data as for all row" mean? What is your problem? You update the records with order_id equal to $_POST["order_id"]. Which records are supposed to be updated? Is that what order_item_hsncode is for? We don't know what your code is supposed to do; you are supposed to know that and you're not telling us.

    And you'd get better performance if you move the prepare() statement to before the loop instead of having it inside the loop.

    Oh, and when you post code, put it in [code]...[/code] blocks so that it isn't an unreadable mess. People aren't going to read unreadable messes.

    Weedpacket
    thanks for the reply. I meant for one order_id there may or may not more than one order item. So when i try to update the order items based on the order_id, For eg: if there is 3 order items for one order_id, it takes the last order item details for the all order items. So in the database table, the last order item details stored for the 3 order items. This is my problem. Hope you understand. thanks.

    Your tbl_order_item table should have an auto-increment id column. You would use this column value when referencing specific row(s) in the table.

      anjanasumesh This is my problem.

      So you need to restrict the update to only the row that is supposed to be updated by putting something in your WHERE clause. Just order_id is obviously not enough because every order item in the order has the same order_id. How you identify individual order items depends on how you've designed the table: if you wanted one particular order item record from tbl_order_item how would you get it?

        5 days later

        If (user, date) is not enough to guarantee uniqueness and there is some other id column that is either unique or primary key (or the (user, date, id) is unique, that's enough), you can do this to keep only one row per user with current=1:

        UPDATE
        ( SELECT DISTINCT user_id
        FROM tableX
        ) AS d
        JOIN
        tableX AS t
        ON t.user_id = d.user_id
        AND (t.date, t.id) <>
        ( SELECT i.date, i.id
        FROM tableX AS i
        WHERE i.user_id = d.user_id
        ORDER BY i.date DESC, i.id DESC
        LIMIT 1
        )
        SET
        t.current = 0 ;
        9Apps Lucky Patcher VidMate

          Write a Reply...