Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11

Thread: updating..?

  1. #1
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post

    updating..?

    How would i make it so it and something to a list? like
    Code:
    update offers ADD ' $usr ' to 'users' where 'name' = '$name'
    So it would come out like

    Admin person *added value*

  • #2
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post
    Would this be correct? i googled it.

    Code:
    mysql_query("update offers set users=concat(users,'$snuid') where name LIKE '%$campname%'");

  • #3
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post
    Seems to work. just one thing, how would i make it so there is a space after the $snuid? it just goes in as value1value2value3

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,133
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    Put the space there, of course.
    Code:
    mysql_query("update offers set users=concat(users,' $snuid') where name LIKE '%$campname%'");
    see the space before the $ of $snuid?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post
    i did that, didnt work. still put it in without the space. doesnt really matter though my other page does like = %$usr% so its fine if there are periods

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,133
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    Okay, force it in:
    Code:
    mysql_query("update offers set users=concat(users,' ','$snuid') where name LIKE '%$campname%'");
    CONCAT can be used to concatenate any number of strings.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    While CONCAT will do what you want, you really shouldn't be storing a list of users in a single field like that. Based on the names I am guessing it is the list of users signed up for an offer? You should use a separate table to link the offers and users together, that will be easier to add and delete users from offers. And to find all the offers that someone is signed up for.
    OracleGuy

  • #8
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,133
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    Teach me to read just code and not the intent!

    Yeah, adding to the list of users like that is brain-dead on many levels.

    Just for starters, what's the size of the users field in that offers table? No matter how big it is, eventually you will run out of space in the field.

    But as OracleGuy points out, one of the first rules of RDBMS usage is NORMALIZE!

    ONE piece of data per field, per record. ONE.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #9
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post
    Sorry i need it like that for it to work.

    How would I delete the names from the string now? It adds them like

    PHP Code:
    mysql_query("update offers set users=concat(users,'.$snuid.') where name LIKE '%$campname%'"); 
    Now, I want it to be like..

    PHP Code:
    remove '$usr' from offers row 'userspending' 
    how would i do that?

  • #10
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post
    im thinkin

    PHP Code:
    mysql_query("update offers set userspending = replace(userspending, '$snuid', ''); 
    will work?

  • #11
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,133
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    No comment. You hit on just one of the many many reasons why putting a list of values into a single field is an el crappo idea.

    And I'm sorry, but I don't believe "i need it like that for it to work." You may need it like that to work in your current bad design. If you'd fix the design, then you wouldn't need or want that stuff.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •