Re: Auto Increment A Field
Usually I let the counter cache do this kind of things, my apps are not so famous that I will run into problems due to high CPU ussage, and nowadays disk space is really cheap. For instance I would create a 'votes' table and model, and store there datetime, user id, ip address and other details of the voter On 13 mar, 23:47, euromark dereurom...@googlemail.com wrote: nice catch :) i guess thats true additionally, updateAll() doesnt trigger any callbacks like beforeSave() or afterSave(). probably a good thing in this case, as well On 13 Mrz., 23:06, Ryan Schmidt google-2...@ryandesign.com wrote: Nick, that code has a race condition. Two different users looking at the page at the same time could cause the count to be incremented by only one total, when you want the count to be incremented by one for each user. The method Krissy showed is atomic and does not have this problem. On Mar 12, 2011, at 11:28, nurvzy wrote: $this-Product-id = 40; $this-Product-saveField('vote', $this-Product-field('vote') + 1); Nick On Mar 12, 9:36 am, Krissy Masters wrote: $this-Product-updateAll(array('Product.vote'='Product.vote+1'), array('Product.id'=40)); -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Auto Increment A Field
Nick, that code has a race condition. Two different users looking at the page at the same time could cause the count to be incremented by only one total, when you want the count to be incremented by one for each user. The method Krissy showed is atomic and does not have this problem. On Mar 12, 2011, at 11:28, nurvzy wrote: $this-Product-id = 40; $this-Product-saveField('vote', $this-Product-field('vote') + 1); Nick On Mar 12, 9:36 am, Krissy Masters wrote: $this-Product-updateAll(array('Product.vote'='Product.vote+1'), array('Product.id'=40)); -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Auto Increment A Field
nice catch :) i guess thats true additionally, updateAll() doesnt trigger any callbacks like beforeSave() or afterSave(). probably a good thing in this case, as well On 13 Mrz., 23:06, Ryan Schmidt google-2...@ryandesign.com wrote: Nick, that code has a race condition. Two different users looking at the page at the same time could cause the count to be incremented by only one total, when you want the count to be incremented by one for each user. The method Krissy showed is atomic and does not have this problem. On Mar 12, 2011, at 11:28, nurvzy wrote: $this-Product-id = 40; $this-Product-saveField('vote', $this-Product-field('vote') + 1); Nick On Mar 12, 9:36 am, Krissy Masters wrote: $this-Product-updateAll(array('Product.vote'='Product.vote+1'), array('Product.id'=40)); -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Auto Increment A Field
Please I would like to know how to increment a field in my database table once an action is viewed. I have a view field in my lyrics table and i want the field to be incremented by one once a visitor click to read a lyrics. I would like to know how this can be implemented. -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
RE: Auto Increment A Field
$this-Product-updateAll(array('Product.vote'='Product.vote+1'), array('Product.id'=40)); So we are updating Product ID = 40 where the vote is vote + 1 increment basically what the above is saying. Original article: http://nuts-and-bolts-of-cakephp.com/2008/05/22/incrementing-a-field-in-cake php/ From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf Of tubiz Sent: Saturday, March 12, 2011 12:36 PM To: cake-php@googlegroups.com Subject: Auto Increment A Field Please I would like to know how to increment a field in my database table once an action is viewed. I have a view field in my lyrics table and i want the field to be incremented by one once a visitor click to read a lyrics. I would like to know how this can be implemented. -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Auto Increment A Field
$this-Product-id = 40; $this-Product-saveField('vote', $this-Product-field('vote') + 1); Nick On Mar 12, 9:36 am, Krissy Masters naked.cake.ba...@gmail.com wrote: $this-Product-updateAll(array('Product.vote'='Product.vote+1'), array('Product.id'=40)); So we are updating Product ID = 40 where the vote is vote + 1 increment basically what the above is saying. Original article: http://nuts-and-bolts-of-cakephp.com/2008/05/22/incrementing-a-field-... php/ From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf Of tubiz Sent: Saturday, March 12, 2011 12:36 PM To: cake-php@googlegroups.com Subject: Auto Increment A Field Please I would like to know how to increment a field in my database table once an action is viewed. I have a view field in my lyrics table and i want the field to be incremented by one once a visitor click to read a lyrics. I would like to know how this can be implemented. -- Our newest site for the community: CakePHP Video Tutorialshttp://tv.cakephp.org Check out the new CakePHP Questions sitehttp://ask.cakephp.organd help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group athttp://groups.google.com/group/cake-php -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Auto Increment A Field
Please I would like to know how to auto increment a field in a table in my database. I want to to be incremented once the action is clicked upon. Thanks. -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Auto Increment A Field
why not just retrieve the value, increment then update the field? On Thu, Feb 24, 2011 at 11:09 PM, tubiz tayi...@gmail.com wrote: Please I would like to know how to auto increment a field in a table in my database. I want to to be incremented once the action is clicked upon. Thanks. -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Auto Increment A Field
On Feb 25, 2011, at 01:16, Robert J. Maiolo wrote: On Thu, Feb 24, 2011 at 11:09 PM, tubiz wrote: Please I would like to know how to auto increment a field in a table in my database. I want to to be incremented once the action is clicked upon. why not just retrieve the value, increment then update the field? Because that's not atomic. (Between the time you retrieve the value and the time you set the new value, another query may have changed the value already.) Instead, you want to have the equivalent of the SQL... UPDATE table SET field=field+1 WHERE somecondition; ...where it all occurs in a single query. How to do this in CakePHP was recently asked in this group; here's one reply from that thread that shows one possible solution: http://groups.google.com/group/cake-php/msg/022622017dd329f8 -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php