{
............
............
$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?

Recommended Answers

All 2 Replies

Member Avatar for ampere

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')";
commented: 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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.