slj90 Posted May 25, 2014 Share Posted May 25, 2014 For example if a row contains "Hello", how would I add " world" to the end of that row using MySQL within PHP without selecting the data from the table? Thanks Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted May 25, 2014 Share Posted May 25, 2014 you can use an UPDATE query with the CONCAT() function to do that. i hope you are not planning on using this to build a delimited list in a column in a database table? Quote Link to comment Share on other sites More sharing options...
slj90 Posted May 25, 2014 Author Share Posted May 25, 2014 you can use an UPDATE query with the CONCAT() function to do that. i hope you are not planning on using this to build a delimited list in a column in a database table? Yes that is what I was going to use it for. Why wouldn't you suggest this and what other ways are there? I am using it to keep track of usernames that have "liked" a status. Thanks, Quote Link to comment Share on other sites More sharing options...
Solution mac_gyver Posted May 26, 2014 Solution Share Posted May 26, 2014 (edited) making a list in a column will require a lot of extra code and queries in order to store values (you must insure they don't already exist in the list), find values, and delete values. the correct method is to have a table that contains one row for each data value. the table would have columns for an id, a 'parent' id (what is being liked), and a 'child' id (who liked it.) the combination of the parent and child id columns would be defined as a unique key. this will enforce uniqueness in the values. to insert a value, you can just insert the new row. if the insert fails with a duplicate key error, you will know that the combination already existed. to find any or all likes by any one or every one, you just query for the child id you want or order by the child id to get all rows by each id together (you would group by the parent or child ids if interested only in a count of likes for an item or a count how many likes someone has given.) to delete any row or rows, you can reference them either by their id, or by the parent id, or the child id values. also, to get the list of actual information, you would use a JOINed query between the above described table and the tables holding the information about the parent and child id's (even if those happen to be the same table, such as a user information table.) Edited May 26, 2014 by mac_gyver Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.