web applications - How to set counter in mysql? -
i have been creating web-application, wanted create counter keep track of pages viewed. so, want create counter in mysql.
scenario this..
if row isn't created, create row
if row created, set counter.
is possible?
or should run 2 queries so.
query 1: run query select table doesn't exist. if returns null, doesn't have data entry.
query 2: so, create entry that, using counter.
query 3: if data created, increment counter.
but there way in single call mysql?
i think want insert . . . on duplicate key update
.
so, have pagesviewed
table sort of page identifier , counter. do:
insert pagesviewed(pageid, counter) select $pageid, 1 on duplicate key update counter = counter + 1;
this requires unique index on pagesviewed(pageid)
.
Comments
Post a Comment