Darnel Posted February 1, 2013 Share Posted February 1, 2013 Hi, I have this code but would like to modify it to be able to insert a new data in the next field if the current one is not empty. global $db; $sql= " UPDATE ".Project ." SET " ." name_1 = '".$user_id."' " ." WHERE project_id = '".$project_id." '"; $db->query($sql); So for example if field "name_1" is occupied I would like to add the same $user_id to "name_2". I've been trying to use CASE WHEN name_1 = '0' but can't seem to get the syntax right and keep getting Mysql errors. Any help appreciated, thanks Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted February 1, 2013 Share Posted February 1, 2013 This is going to sound all negative, but you should not have columns in a database with names like - name_1, name_2, ... that store same meaning data. Doing so makes writing any query and code that manipulates that data, difficult. Which you have found to be the case with your UPDATE query. Same meaning data should be store as one row per data item. You can then easily write a query to find, store, or change just that one data item or any or all the related data items. 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.