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 8111631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:11:36+00:00 2026-06-06T02:11:36+00:00

I have a HTML form that accepts a comma separated list of tags, which

  • 0

I have a HTML form that accepts a comma separated list of tags, which works just like the one here on stackoverflow. I also have a MySQL table that contains lists of tags that belong to each user. The user can update their tags in their profile, so what I would like to do is automatically remove any tags from the MySQL table if it no longer exists in the list

For example, the user enters the following on the web form:

trance, house, electronica, dubstep, club

The MySQL table however, has this

userid    tag
1         trance
1         house
1         electronica
1         dubstep
1         garage

I would like to remove the garage tag from MySQL and add “club” instead.

It is also worth noting that while these tags appear in order in my example above, this won’t always be the case, so I can’t rely on the array index position in both, for example.

I realise I could probably loop through the comma separated list with a foreach and generate a delete statement, and re-insert all the tags from scratch but I feel that there is probably a better way to do this.

Thanks in advance for your guidance.

Dave

  • 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-06T02:11:37+00:00Added an answer on June 6, 2026 at 2:11 am

    You need only to place (after properly escaping and quoting) your comma separated list into a NOT IN() clause and use it in a DELETE statement like the following. The order doesn’t matter.

    DELETE FROM tags WHERE userid = 1 AND tag NOT IN ('trance', 'house', 'electronica', 'dubstep', 'club');
    

    How you go about escaping and quoting the comma-separated values will depend on the database API you are using, be it PDO, MySQLi, or the old (and soon to be deprecated) mysql_*() functions.

    I’ll note that you’ve done the right thing by storing tags one per row, rather than storing them as the CSV list in a single column.

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

Sidebar

Related Questions

I have a HTML form that has certain fields which i am opening inside
I have an HTML form that needs multiple submit buttons, like this: <input type=submit
I have a simple html form that looks like the following <form action=search.php method=get>
I have a simple html form that is structured something like this: <form name=test
I do have an html form that accepts textbox input of sha1 hashes per
I have a HTML form, and I have a Controller Action that accepts the
I have a following problem, I have HTML form that uploads a file with
I have a html form that posts to a new page on submit. If
Okay, next PHPExcel question. I have an HTML form that users fill out and
I have an html/php form that updates entries on the database server. I need

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.