06-14-2017, 11:35 AM
Hmm. I'm not sure exactly what you're talking about. You don't need anything special to do this.
You want to tie the two tables together with some sort of id, so...
Let's just say you have table 1 called master, your columns would look like
id (int 11, auto incremented)
//then whatever other columns you want
Then I'm assuming that you want table two to possibly have many lines that all connect to the master table. This one is called details
That one would have
id (int 11, auto incremented)
master_id (int 11)
//then whatever other columns you want
So, you would do your inserts in two steps...
THEN you need to get that id back
So now you do your second query
This video is about 30 minutes, but I think it will save you a lot of time in the long run...
https://userspice.com/documentation-db-class/
You want to tie the two tables together with some sort of id, so...
Let's just say you have table 1 called master, your columns would look like
id (int 11, auto incremented)
//then whatever other columns you want
Then I'm assuming that you want table two to possibly have many lines that all connect to the master table. This one is called details
That one would have
id (int 11, auto incremented)
master_id (int 11)
//then whatever other columns you want
So, you would do your inserts in two steps...
Code:
$fields = array(
Code:
your_data=>"the_actual_data"
Code:
);
Code:
$db->insert('master',$fields);
Code:
$master_id = $db->lastId();
So now you do your second query
Code:
$fields2 = array(
Code:
master_id = $master_id,
Code:
your_data=>"the_actual_data"
Code:
);
Code:
$db->insert('details',$fields2);
This video is about 30 minutes, but I think it will save you a lot of time in the long run...
https://userspice.com/documentation-db-class/