0

For example I have a loop that will execute an INSERT on each iteration.

Assuming data model is : "isTitle", "content", "parent_id"

The input data is a list of title and paragraphs.

I want to store them in the above data model while keeping their relationships to each other (only the parent_id).

For example, the first iterated node is a title, its parent_id is NULL because it's the first title of the document.

The second element is a paragraphe, so isTitle is NULL, but parent_id should be the ID of the last iterated title.

How do I get that ID value given the fact that the whole process is happening in a loop ?

lapin
  • 2,098
  • 2
  • 21
  • 30
  • Possible duplicate of [LAST\_INSERT\_ID() MySQL](https://stackoverflow.com/questions/3837990/last-insert-id-mysql) – caramba Feb 23 '18 at 04:34
  • It’s not necessarily last inserted because there can be several paragraphs in a row – lapin Feb 23 '18 at 04:44
  • Do you also have a `id` field where you use `AUTO_INCREMENT`? Can you also share some dummy code of `the whole process is happening in a loop` thanks – caramba Feb 23 '18 at 05:34

0 Answers0