Professional Web Applications Themes

How to implement a counter? - MySQL

Hi, I want to implement a hit counter using SQL. I was going to just have one per day in the year. I would like it if there were an atomic incrementer in SQL so that if a numeric column let's say had a value of 5, I could just automatically increment it to 6 with one SQL command, without worrying about doing a select, delete, and insert, which could be interrupted. Is there a command for this, however? Thanks....

  1. #1

    Default How to implement a counter?

    Hi,
    I want to implement a hit counter using SQL.
    I was going to just have one per day in the year.
    I would like it if there were an atomic incrementer
    in SQL so that if a numeric column let's say
    had a value of 5, I could just automatically
    increment it to 6 with one SQL command,
    without worrying about doing a select, delete,
    and insert, which could be interrupted.
    Is there a command for this, however?
    Thanks.

    Flarky Guest

  2. #2

    Default Re: How to implement a counter?

    Flarky wrote:
     


    UPDATE table SET col = col+1 WHERE ...;


    --
    Brian Wakem
    Email: http://homepage.ntlworld.com/b.wakem/myemail.png
    Brian Guest

  3. #3

    Default Re: How to implement a counter?

    > UPDATE table SET col = col+1 WHERE ...;

    Depending on the version used (>4.1, I think), you can even
    Combine an insert with an update:

    INSERT INTO SomeTable(CounterName, Hits) VALUES('JustAName', 1) ON
    DUPLICATE KEY UPDATE Hits = Hits + 1;

    You'd need a uniqueness constraint on the CounterName column for this to
    work.

    Best regards
    Dikkie Guest

Similar Threads

  1. How to implement a MXP
    By MikeMedia2 in forum Macromedia Exchange Dreamweaver Extensions
    Replies: 1
    Last Post: June 9th, 08:56 PM
  2. RFC: DBIx::Counter - persistent counter class
    By Rhesa Rozendaal in forum PERL Modules
    Replies: 0
    Last Post: April 14th, 12:15 AM
  3. Free Network Tools - Random Password Generator - Link Counter - Hit Counter
    By FreewareTown.com in forum Linux / Unix Administration
    Replies: 0
    Last Post: August 30th, 09:20 AM
  4. hit counter or page counter
    By Myothello in forum Web Design
    Replies: 3
    Last Post: April 23rd, 10:15 PM
  5. How to implement counter?
    By Tom Vande Stouwe MCSD.net in forum ASP.NET General
    Replies: 1
    Last Post: July 24th, 05:22 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139