I'm retrieving last id of tbl_orderdetail(table 1) in order to add addon items entries into tbl_orderdetail_addon(table 2). Basically it should insert into (table 2) as per the number of ids received from (table 1). I'm using mysql_insert_id() for that.
i'm getting that right but the ids are not looping through. It inserts the same id of (table 1) for all entries in (table 2). Say that I have two entries in (table 1),obviously it should return 2 id's.And each id has 2 add on items .So in (table 2) there should be four entries with 2 different id's of (table 1). IN my case Im getting 4 entries of same id of (table 1).
Here's my coding:
$o_id_detail=mysql_insert_id();//(table 1) id
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());
}
}
}
Any help would be greatly appreciated.Thanks in advance.