Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7863437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:28:57+00:00 2026-06-02T23:28:57+00:00

I’m asking this again, because I can’t get a straight answer from other questions

  • 0

I’m asking this again, because I can’t get a straight answer from other questions on SO.

My situation is as follows, two tables, phones and features.

Structure:

phones

  • id
  • brand_id
  • model
  • picture
  • published

features

  • id
  • phone_id
  • feature

Now, features contains a whole lot of values, which only between 1 & 4 will correspond to a certain phone via phone_id.

Now, when I update features, do you think deleting and then inserting new features again or updating existing features will be best?

// edit:

specials

  • id*
  • phone_id
  • contract_id
  • start_publish
  • finish_publish
  • published

contract

  • id*
  • name
  • benefit
  • duration
  • price, etc.

brand

  • id
  • name
  • logo

So basically, a special links a phone and a contract together, and grabs info from both tables for output. Then during that process, each phone’s features get loaded separately using a function.

// edit 2:

Oh, and only one phone’s features will be deleted/updated at a time, and also, only between 1-4 features will be deleted at a time. Also, features can always be more or less, and never a set number.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T23:28:58+00:00Added an answer on June 2, 2026 at 11:28 pm

    If the number of features per phone will ever change, then you must delete and insert. To update, you’d need to:

    • get the current set of features
    • figure out what is different, what was added, and what was removed
    • run queries to update, insert new data, and delete old data.

    Where as if you just delete the whole list and re-insert them, you save yourself some maintenance headaches.

    If consistency of your data is an issue or concern (the data is deleted but an error happens before insert causing the script to not complete) then wrap your queries in a transaction.

    Take this example:

    I have a blog with Posts(id, title, body) and Categories(id, post_id, category). My first Post, “Hello World” is categorized under “meta, php, and javascript”. Then a year later, I revise the post to have some information about mysql (or I add a mysql category) and take out javascript.

    Here’s what I’d need to do (mostly psuedocode):

    //old set
    SELECT * FROM Categories WHERE post_id=1
    
    foreach($categories as $category) {
        if(in_array($category['id'], $_POST['categories']) {
            //this category is in the new set and the old set, do nothing
        }
        elseif(!in_array($category['id'], $_POST['categories']) {
            //this category is in the old set, but not the new one, delete it
            $queries[] = "DELETE FROM Categories WHERE id=".$category['id'];
        }
        else {
            //new category, add it
            $queries[] = "INSERT INTO Categories()..."
        }
    }
    
    foreach($queries as $item) {
        //run query
    }
    

    Versus this:

    DELETE FROM Categories WHERE post_id=$_POST['id']
    
    foreach($_POST['categories'] as $item) {
        INSERT INTO Categories() ...
    }
    

    Personally, I think option #2 is better.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know how can I replace this 2 symbol below from the string
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am currently running into a problem where an element is coming back from
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.