Hello All,
Hoping someone with a little more experience than myself maybe able to help.
I've been stuck on this issue with my code for months now, and it's started hurting my head thinking about it.
Can anybody offer any guidance / advise / anything at all to help me on my way?
-----
I'm writing a web application, which will be eventually used for a construction company.
The application successfully allows users to produce quotes for costing purposes.
I'm stuck, because I need to be able to duplicate a quotation, and all sub-tables with linked keys.
This will create a new version of the quote which we can edit separately.
I've managed to duplicate the first table, and the subsequent table with the linked keys.
However, I'm struggling to duplicate the rows on the third table, and have them linked to the second.
I may be doing this all wrong, but can anyone advise?
Hoping someone with a little more experience than myself maybe able to help.
I've been stuck on this issue with my code for months now, and it's started hurting my head thinking about it.
Can anybody offer any guidance / advise / anything at all to help me on my way?
-----
I'm writing a web application, which will be eventually used for a construction company.
The application successfully allows users to produce quotes for costing purposes.
I'm stuck, because I need to be able to duplicate a quotation, and all sub-tables with linked keys.
This will create a new version of the quote which we can edit separately.
I've managed to duplicate the first table, and the subsequent table with the linked keys.
However, I'm struggling to duplicate the rows on the third table, and have them linked to the second.
I may be doing this all wrong, but can anyone advise?
PHP:
//FIRST TABLE INSERT:
//KEY FOR TABLE ONE: quote_id > LINKED TO TABLE TWO
$query = "
INSERT INTO quotes (customer, quote_contact, enquirey, quote_name, quote_date, quote_status)
SELECT customer, quote_contact, enquirey, quote_name, quote_date, quote_status
FROM quotes
WHERE quote_id = :version_quote
";
//:version_quote is a btn
$statement = $connect->prepare($query);
$statement->execute(
array(
':version_quote' => $_POST["version_quote"]
)
);
$result = $statement->fetchAll();
//SECOND TABLE INSERT:
//KEY FOR TABLE TWO: quote_details_id > LINKED TO TABLE THREE
//FOREIGN KEY FOR TABLE TWO: quote_id > LINKED TO TABLE ONE
$query = "
INSERT INTO quote_details (quote_id, quote_details_desc, quote_details_quantity)
SELECT LAST_INSERT_ID(), quote_details_desc, quote_details_quantity
FROM quote_details
WHERE quote_id = :version_quote
";
$statement = $connect->prepare($query);
$statement->execute(
array(
':version_quote' => $_POST["version_quote"]
)
);
$result = $statement->fetchAll();
// THIRD TABLE INSERT:
//PRIMARY KEY FOR TABLE THREE: qd_item_id
//FOREIGN KEY FOR TABLE THREE: qd_quote_details_id > LINKED TO TABLE TWO
$query = "
INSERT INTO qd_items (...)