Make a row increase every time the same value is added to th

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dominod
Forum Commoner
Posts: 75
Joined: Wed Jun 30, 2010 7:18 am

Make a row increase every time the same value is added to th

Post by dominod »

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 :)
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Make a row increase every time the same value is added t

Post by Benjamin »

One solution would be to add a unique index to the name field, or whatever it is, then use the ON DUPLICATE KEY UPDATE mysql syntax. You can find examples of this on the mysql website.
dominod
Forum Commoner
Posts: 75
Joined: Wed Jun 30, 2010 7:18 am

Re: Make a row increase every time the same value is added t

Post by dominod »

Thanks :D
Post Reply