Datawriter how to find missing items to remove?

Marcus

Well-known member
Imagine I have receipts for Pizzas. And a template form where I can edit its ingredients. I add Basilikum to the receipts textarea:
Tomatoes
Mozzarella
Basilikum

and save it. The Basilikum is added to the Margharita item. Now I edit the form and its textarea again to
Tomatoes
Mozzarella

The Controller saves these two items (and knows they already exist with the getIngredients('Margharita','Tomatoe') and the same check for Mozzarella) but how would he know that he should remove Basilikum?

How do you code this in the most easy way?
 
Hmm, this may depend how the data is being arranged in the database.

Are the ingredients all kept in the same row and column in the database?

Is each ingredient in its own row?
 
These are the tables:

Pizza: id, pizza-id, title
Ingredients: id, ingredient-id, title
Pizza-Ingredient: id, pizza-id, ingredient-id
 
The first id's for pizza and ingredient are for the dw. I guess I should remove them and only use their more specific second counterparts. But what is it with the third table, using a dw I guess the id is necessary? I much prefer mysqls unique table over the last entries where no id is needed.
 
There are a lot of ways to do it.
You can do a input text for each ingredient with a delete button for each one. When the user press it the form will delete the Pizza-Ingredient row where id = x.
Another way is (more resource) $db->fetchAll from Pizza-Ingredient where pizza-id = x, compare it with the new array and delete/create the difference.
 
Back
Top Bottom