0

I Fetch this data from Tags Table with comma separated :

trance, house, electronica, dubstep, club

Tags Table Is:

ID        NAME             ArticleId
1         trance              10
2         house               10 
3         electronica         10
4         dubstep             10
5         garage              10

Now I need To UPDATE Tags Table With This New Input For Edit Page:

trance, house, electronica  // I remove dubstep, club tag

My PHP Code:

$arr_tag = explode(",",$tag); 
   foreach($arr_tag as $tags){
      DataAccess::put("UPDATE tags SET name = ?, type=? WHERE article = 10",$tags,"news");
   }

Now After UPDATE Ouput Is:

trance, trance, trance

My Problem Is: How To UPDATE Tags Table For New Tag Input?

1
  • done any basic debugging yousrelf, e.g. var_dump($tag), and var_dump($arr_tag) to see what you're working with? As well, note that your update query will simply set ONE tag each time, replacing the tag that was set in the previous update. Commented Oct 18, 2013 at 18:01

2 Answers 2

1

You have to delete all informations first:

query = "DELETE FROM tags WHERE article = 10"

Then you save all rows again. Very easy

Sign up to request clarification or add additional context in comments.

Comments

1

The problem is that your update query is replacing any rows who its article is 10 with whatever tag is the current one in the foreach loop, and the end result is that you're replacing them with the last value of your tags array. I recommend you to first delete all the relevant rows then insert them again with the information you want, but in top of all, I recommend you to read more about PHP and SQL queries in general, as you seems to be lacking in both.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.