1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Datawriter how to find missing items to remove?

Discussion in 'XenForo Development Discussions' started by Marcus, Nov 4, 2012.

  1. Marcus

    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:

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

    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?
  2. Chris D

    Chris D XenForo Developer Staff Member

    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?
    Marcus likes this.
  3. Marcus

    Marcus Well-Known Member

    These are the tables:

    Pizza: id, pizza-id, title
    Ingredients: id, ingredient-id, title
    Pizza-Ingredient: id, pizza-id, ingredient-id
  4. Marcus

    Marcus Well-Known Member

    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.
  5. Lu Jia

    Lu Jia Active Member

    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.
    Marcus likes this.

Share This Page