I've two tables in my joomla 2.5
site component that trying to inset two tables and first table ID should be second table foreign-key
.
Table: MYTABLE
-------------------------------------------------------------
| mytab_id | mytab_name | mytab_country | mytab_city |
-------------------------------------------------------------
Table: YOURTABLE
-------------------------------
| yourtab_id | group_name |
-------------------------------
mytab_id
is auto increment
value and that should insert to second table yourtab_id
as foreign-key
.
How should I insert data to both tables as first table id value to second table id.
I've tried below code but it doesn't work.
$insert_query = "INSERT INTO #__mytable (mytab_name, mytab_country, mytab_city) VALUES ('". $mytab_name."',".$mytab_country.",'".$mytab_city."'); ";
$db->setQuery( $insert_query );
$db->query();
$insert_query2 = "INSERT INTO #__yourtable (yourtab_id, group_name) VALUES (".LAST_INSERT_ID().", 2);";
$db->setQuery( $insert_query2 );
$db->query();
Thanks,