0
{
............
............
$order_details="INSERT INTO .....";
mysql_query($order_details);
$o_id_detail[]=mysql_insert_id();
}

$prev_id=implode(',',$o_id_detail);
$last_id=explode(',',$prev_id);
foreach($last_id as $last)
{
    $last;
    foreach($addon_price as $a_p=>$p)
    { 
        echo $a_p;
        foreach($p as $m)
        {

            $addon_id= $m['id'];
            echo $m['addon_name'];
            echo $m['deposit'];
            echo $m['ppd'];
            echo $m['pp_eight'];
            echo $m['pp_six'];

            $addon_total = $m['deposit']+$m['ppd']+$m['pp_eight']+$m['pp_six'];
            echo $addon_total;

            $addon_detail="INSERT INTO tbl_orderdetail_addon 
                                (OrderID,addOns_id,addOns_price) 
                            VALUES ('$o_id_detail','$addon_id','$addon_total')";
            if(!empty($addon_id)){
                mysql_query($addon_detail)or die(mysql_error());
            }
        }     
   }   
}
}

Now, Im getting ($last) inserted as many times as the foreach loops( foreach($addon_price as $a_p=>$p)).
How to restrict $last id form inserting any rows again if the ($last)id for a specific addon_item already exist?

Edited by Kalaivani Nair: added codes

3
Contributors
2
Replies
37
Views
3 Years
Discussion Span
Last Post by matrixdevuk
1

you should use $last instead of $o_id_detail in the below code

$addon_detail="INSERT INTO tbl_orderdetail_addon
(OrderID,addOns_id,addOns_price)
VALUES ('$last','$addon_id','$addon_total')";
Votes + Comments
hmm I used $last..it's just a typo error..Thank u for highlighting
0

Why not just use an Auto Increment value?!

Feature is there

Doesn't take it

Edited by matrixdevuk

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.