rmelino Posted February 21, 2011 Share Posted February 21, 2011 Hello, I am having trouble writing a function in php/mysql to perform an operation on all records within my sql database. In it's simplest form, here is what i'm trying to do: my table looks like this: id | name | dogs | cats | total_animals 1 | john | 3 | 2 | 2 | paul | 4 | 2 | etc On submit of a form, in I would like to update all the rows in the table above and have the 'total_animals' field filled in with the value from adding together dogs + cats for that row. Thanks in advance for any help you can provide. I'm sure this is simple but I must be missing something since I haven't had any luck with it! Quote Link to comment Share on other sites More sharing options...
requinix Posted February 21, 2011 Share Posted February 21, 2011 Why do you need a field for that? You can easily figure out the value by adding dogs+cats - you don't need to store it anywhere. Quote Link to comment Share on other sites More sharing options...
rmelino Posted February 21, 2011 Author Share Posted February 21, 2011 Well the value i'm actually going to be putting in here is more complicated than the example i gave. I'm just looking for how to do this example and then i should be able to expand on that to apply it to my actual table... Quote Link to comment Share on other sites More sharing options...
rmelino Posted February 21, 2011 Author Share Posted February 21, 2011 As i'm reading up on this perhaps a stored procedure is a better way to go? Quote Link to comment Share on other sites More sharing options...
fenway Posted February 23, 2011 Share Posted February 23, 2011 Same question applies... 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.