phppup Posted March 2, 2012 Share Posted March 2, 2012 I got to thinking late last night (which generally leads to trouble), so please be gentle if some educating is in order, as I suppose I will touch a few related issues. As I develop my database, I will include two seperate columns. One for the time/date that an order was placed. A second for the time/date that an order is updated (unless there's a better way, please inform me). I pressume that if a record is updated several times, it will continually overwrite the time/date to the point that I will only see the latest update. Now I was wondering if I could create a third column to keep count of the number of times a record had been updated, so if it were altered 16 times, I would know when the last update occurred, and have the count number also. Will something like this coding work? SELECT updates FROM myTable WHERE id="$id" $updates =n if n<1, n=1 }else{ n++ Quote Link to comment https://forums.phpfreaks.com/topic/258137-count-number-of-updates/ Share on other sites More sharing options...
Proletarian Posted March 2, 2012 Share Posted March 2, 2012 Sounds like it would work. But why check if updates are less than 1? Set it so it defaults to 0, then just increment by 1 every time an update occurs. Quote Link to comment https://forums.phpfreaks.com/topic/258137-count-number-of-updates/#findComment-1323225 Share on other sites More sharing options...
phppup Posted March 2, 2012 Author Share Posted March 2, 2012 Don't know how to do what you suggested, so I went with what I could think of.. LOL Quote Link to comment https://forums.phpfreaks.com/topic/258137-count-number-of-updates/#findComment-1323231 Share on other sites More sharing options...
Proletarian Posted March 2, 2012 Share Posted March 2, 2012 You can default values in your table to some kind of value when you define your table. Quote Link to comment https://forums.phpfreaks.com/topic/258137-count-number-of-updates/#findComment-1323232 Share on other sites More sharing options...
phppup Posted March 2, 2012 Author Share Posted March 2, 2012 But then how do you get them to increment? Quote Link to comment https://forums.phpfreaks.com/topic/258137-count-number-of-updates/#findComment-1323237 Share on other sites More sharing options...
Proletarian Posted March 2, 2012 Share Posted March 2, 2012 But then how do you get them to increment? By getting the current value from the database then adding 1 to it. Quote Link to comment https://forums.phpfreaks.com/topic/258137-count-number-of-updates/#findComment-1323244 Share on other sites More sharing options...
phppup Posted March 2, 2012 Author Share Posted March 2, 2012 How would i code if I wanted to do as you suggested and; just increment by 1 every time an update occurs. Quote Link to comment https://forums.phpfreaks.com/topic/258137-count-number-of-updates/#findComment-1323248 Share on other sites More sharing options...
Proletarian Posted March 2, 2012 Share Posted March 2, 2012 Select your row, from that row, get the number of updates, add 1 to it, then update your row. Quote Link to comment https://forums.phpfreaks.com/topic/258137-count-number-of-updates/#findComment-1323253 Share on other sites More sharing options...
phppup Posted March 2, 2012 Author Share Posted March 2, 2012 Isn't that what I did. Are you trying to be a wiseguy and waste my time, or do you have an actual solution to suggest to improve my code? If so, please POST IT! Quote Link to comment https://forums.phpfreaks.com/topic/258137-count-number-of-updates/#findComment-1323261 Share on other sites More sharing options...
Proletarian Posted March 2, 2012 Share Posted March 2, 2012 Isn't that what I did. Are you trying to be a wiseguy and waste my time, or do you have an actual solution to suggest to improve my code? If so, please POST IT! I'm not going to write code for you, sorry. If you already did it, then this topic is finished. Quote Link to comment https://forums.phpfreaks.com/topic/258137-count-number-of-updates/#findComment-1323264 Share on other sites More sharing options...
Pikachu2000 Posted March 2, 2012 Share Posted March 2, 2012 What happened when you tried your code? Did it work or not? Quote Link to comment https://forums.phpfreaks.com/topic/258137-count-number-of-updates/#findComment-1323265 Share on other sites More sharing options...
phppup Posted March 2, 2012 Author Share Posted March 2, 2012 Hey Pik! Haven't had a chance to plug it in. It'll have to wait til another day, but I wanted to see if I was on the rigth track. What do YOU think of it? Quote Link to comment https://forums.phpfreaks.com/topic/258137-count-number-of-updates/#findComment-1323267 Share on other sites More sharing options...
Pikachu2000 Posted March 2, 2012 Share Posted March 2, 2012 I think you should increment a field every time an UPDATE query is executed. It can all be done at one time; there's no need for a SELECT query ahead of time. The syntax is here: http://dev.mysql.com/doc/refman/5.0/en/update.html in the third grey highlighted code block. Quote Link to comment https://forums.phpfreaks.com/topic/258137-count-number-of-updates/#findComment-1323271 Share on other sites More sharing options...
phppup Posted March 2, 2012 Author Share Posted March 2, 2012 will check it tomorrow. But thanks! Took a quick look and it seems to simplify the process. Enjoy the weekend. Quote Link to comment https://forums.phpfreaks.com/topic/258137-count-number-of-updates/#findComment-1323278 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.