Match items in MySQL imploded array to PHP array in query -


I am a database noob, how can I search for rows by matching items in a PHP array, in MySQL Array Array Items? It is stored like this feature, but if I want to do what I want, I have all the ears, I am looking for something like this (I use * * To say where I'm joining hands):

  $ sql = "select * from codenit"; $ Sql = "WHERE when made private = 1 then Manufacturer ID =: User ID ELSE True ED"; If (isset ($ tag)) {$ tag_ids = join (',', $ tag); $ Sql = "And **** mysql item in the array 'tag' IN: tag"; If ($ stmt = $ this-> _db- & gt; Ready ($ sql)) {$ stmt- & gt; BeyondParam (": userID", $ userID, PDO :: PARAM_STR); $ Stmt- & gt; Bind Parmum (": Tag", $ Tag_Ieds, PDO :: Param_st); $ Stmt- & gt; Executed (); $ Stmt- & gt; CloseCursor (); }}   

Here's how I am storing items in DB. $ Value tag is bound to query the column, so why am I calling it mysq array?

  $ tag = array (); Foreign currency ($ _POST ['tag'] for $ selected option) {$ tag [] = $ selected option; } $ Values ​​= implode (",", array_values ​​($ tag)); $ Sql ​​= "INSERT" "Codenet (tag)". "Value (: tag)"; If ($ stmt = $ this-> _db- & gt; Ready ($ sql)) {$ stmt- & gt; Tie Para (": Tag", $ value, PDO :: param_st); $ Stmt- & gt; Executed (); $ Stmt- & gt; CloseCursor (); Back true; }   

This is the result of an entry in my DB that looks like 'Tag1, Tag2, Tag 3'. Very simple string

This is not a good database design for this kind of query, you have to find a tag Like to

Instead, you should have a "tag" table with one tag per line, then you can use the "IN" statement to include:

  SELECT * Tag tags on codenotes tags codunit_id = codeunits.id where tags are named (IN) and case when private = 1 then creatorID =: userID ELSE true end    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -