dominod Posted July 27, 2010 Share Posted July 27, 2010 Hi Is it possible to make a row(with number) increase every time the same value is added to the table? Example: I enter "test" into a table and it gets the following data: id=1 name=test count=1 And the next time I enter "test" into the table it becomes id=1 name=test count=2 instead of id=1 name=test count=1 id=2 name=test count=1 I want to create a form where users can suggest stuff and I want to see what is the most popular ect. Thanks in advance Link to comment https://forums.phpfreaks.com/topic/209003-make-a-row-increase-every-time-the-same-value-is-added-to-the-table/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 27, 2010 Share Posted July 27, 2010 The INSERT query has an ON DUPLICATE KEY UPDATE option that will allow you to do this - INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [iGNORE] [iNTO] tbl_name [(col_name,...)] {VALUES | VALUE} ({expr | DEFAULT},...),(...),... [ ON DUPLICATE KEY UPDATE col_name=expr [, col_name=expr] ... ] Link to comment https://forums.phpfreaks.com/topic/209003-make-a-row-increase-every-time-the-same-value-is-added-to-the-table/#findComment-1091669 Share on other sites More sharing options...
Jessica Posted July 27, 2010 Share Posted July 27, 2010 Another way to do this would be using the COUNT(field) when later needing to know how many of each value there is. That way you could keep unique records of who suggested what, to prevent duplicates or "spam". You could also do it in PHP using array_count_values. Link to comment https://forums.phpfreaks.com/topic/209003-make-a-row-increase-every-time-the-same-value-is-added-to-the-table/#findComment-1091670 Share on other sites More sharing options...
dominod Posted August 1, 2010 Author Share Posted August 1, 2010 Thanks alot guys Link to comment https://forums.phpfreaks.com/topic/209003-make-a-row-increase-every-time-the-same-value-is-added-to-the-table/#findComment-1093892 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.