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

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -