Filter out elements of a mysql text field for an update statement?

Discussion in 'PHP' started by phantom, Nov 18, 2008.

  1. #1
    I have a text field in a mysql database with data like this:

    1929, 929, 884, 1001, 2001, 11001,


    How can I use PHP to update that feild and remove a particular element?
    (in a mysql update statement)

    For instance take out "929," in the above example data?


    I have to be sure only the exact element is taken out.


    Any ideas?

    Thanks in advance!
     
    phantom, Nov 18, 2008 IP
  2. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #2
    you mean, you will execute that in 2 queries.. why not one

    update table (select column from table where value = '929') values ('new value');

    thats it ^_^
     
    bartolay13, Nov 18, 2008 IP
  3. phantom

    phantom Well-Known Member

    Messages:
    1,509
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    140
    #3
    Hmm, I don't think that is it either....

    see....all these 1929, 929, 884, 1001, 2001, 11001, are in a column of type TEXT

    so whole table looks like this


    +----+-----------+------------+-------------------------------------------+
    | id | user           |             items         |   timeUpdate             |
    +----+-----------+------------+-------------------------------------------+
    |  2 | 626423142 | 1929, 929, 884, 1001, 2001, 11001, | 2008-11-18 23:33:59 | 
    +----+-----------+------------+-------------------------------------------+
    
    Code (markup):
    "items" column is type TEXT so how do I replace 929 without clobbering 1929 ...or replace any of those elements without clobbering the others and without clobbering any parts of the others?


    I'm guessing I need to populate an array with all the numbers I need to save from the column then update the column with the new array. Anyone have any idea how I would go about this?
     
    phantom, Nov 18, 2008 IP
  4. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #4
    ow.. it thought it is separate columns.. this will deal more on string manipulation

    heres an example :

    $vowels = array("a", "e", "i", "o", "u", "A", "E", "I", "O", "U");
    $onlyconsonants = str_replace($vowels, "", "Hello World of PHP");
    // Provides: Hll Wrld f PHP
     
    bartolay13, Nov 18, 2008 IP
  5. phantom

    phantom Well-Known Member

    Messages:
    1,509
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    140
    #5
    nevermind I figured it out........I used array_push to push a new set elements back into the field. So it works now. Thanks for helping!
     
    phantom, Nov 18, 2008 IP