View Full Version : updating..?
09-21-2011, 11:16 PM
How would i make it so it and something to a list? like
update offers ADD ' $usr ' to 'users' where 'name' = '$name'
So it would come out like
Admin person *added value*
09-21-2011, 11:35 PM
Would this be correct? i googled it.
mysql_query("update offers set users=concat(users,'$snuid') where name LIKE '%$campname%'");
09-21-2011, 11:40 PM
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
09-22-2011, 03:40 AM
Put the space there, of course.
mysql_query("update offers set users=concat(users,' $snuid') where name LIKE '%$campname%'");
see the space before the $ of $snuid?
09-22-2011, 03:46 AM
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
09-22-2011, 04:53 AM
Okay, force it in:
mysql_query("update offers set users=concat(users,' ','$snuid') where name LIKE '%$campname%'");
CONCAT can be used to concatenate any number of strings.
09-22-2011, 06:30 PM
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.
09-22-2011, 06:47 PM
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.
09-24-2011, 01:24 AM
Sorry i need it like that for it to work.
How would I delete the names from the string now? It adds them like
mysql_query("update offers set users=concat(users,'.$snuid.') where name LIKE '%$campname%'");
Now, I want it to be like..
remove '$usr' from offers row 'userspending'
how would i do that?
09-24-2011, 01:35 AM
mysql_query("update offers set userspending = replace(userspending, '$snuid', '');
09-24-2011, 05:15 AM
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.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.