Basically you'd have a DB set up like this:

   hits_table                                  main_table
+--------------+                           +-----------------+
|     id       | (long int) <------------- |      id         |
+--------------+                           +-----------------+
|  num_hits    | (long int)                |     foobar      |
+--------------+                           +-----------------+
| date_created | (date/time)               |     bar         |
+--------------+   optional! :)            +-----------------+

<Untested code>
So when you want to create a new record you'd do:

1) Lock the table "hits_table"
2) Check to see if the ID already exists in the hits_table
   SELECT * FROM hits_table WHERE id = (your id here)
   If Id exists, then just update
      UPDATE hits_table SET num_hits = num_hits + 1 WHERE id = (your
id)
   else
      INSERT INTO hits_table(id, num_hits) VALUES (123, 1);
   end if

   Optionally when you check to see if the ID exists, you might want
to
   check for today's date as well. That is if you wanted to keep the
   histical records of all your hits. This will come in handy
   when you do your reporting ie you can get a break down of all
   hits per day, month, year etc etc. So do that your SQL
   would be something like

   SELECT * FROM hits_table WHERE id = (your id here) AND
   Date(date_created) = CURRDate()

   If Id exists, then just update
      UPDATE hits_table SET num_hits = num_hits + 1
      WHERE id = (your id) AND TO_DAYS(date_created) = TO_DAYS(NOW());
   else
      INSERT INTO hits_table(id, num_hits, date_created) VALUES (123,
1, NOW());
   end if

3) Unlock the table "hits_table"

</Untested code>

HTH

> Opec,
>       Thanks for the response. I will lock the table. That
> would be important
> because I have 3 different websites pulling the same info.
> Do you have an
> example that would help me know how to get started setting
> that up or a link
> perhaps?
> Thanks a ton.
> Alan
>


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to