MySQL database to support simple graphical counters

Source: Internet
Author: User

This article mainly describes how to use the MySQL database and GD to support simple graphic counters, I have seen the following articles from a reputable website. I believe the following articles will be helpful to many people.

<? Php

Only one hit_count field in the hit_count table

The page_visit_record table is used to control one IP address to generate only one counter in a day.

 
 
  1. Create table page_visit_record (
  2. Visit_time datetime DEFAULT '2017-00-00 00:00:00 'not null,
  3. Remote_addr char (15) not null,
  4. Visit_page char (60) not null,
  5. KEY visit_time (visit_time, visit_page ),
  6. Prima (the most comprehensive virtual host Management System) ry key (visit_time)
  7. );
  8. ***/
  9. Include ("config. inc. php3 ");
  10. $ Query = "select count (*) as tong from page_visit_record where remote_addr = '$ REMOTE_ADDR' and date_format (visit_time, '% Y-% m-% D') = curdate () ";
  11. $ Result = @ MySQL (the best combination with PHP) _ query ($ query, $ dbconnect );
  12. $ Has_count = @ MySQL (the best combination with PHP) _ result ($ result, 0, "tong ");
  13. @ MySQL (the best combination with PHP) _ query ("lock tables hit_count write", $ dbconnect );
  14. $ Query = "select * from hit_count ";
  15. $ Result = @ MySQL (the best combination with PHP) _ query ($ query, $ dbconnect );
  16. If (@ MySQL (the best combination with PHP) _ num_rows ($ result)> 0 ){
  17. $ Cur_count = @ MySQL (the best combination with PHP) _ result ($ result, 0, "hit_count ");
  18. If ($ has_count = 0 ){
  19. $ Cur_count ++;
  20. $ Query = "update hit_count set hit_count = '$ cur_count '";
  21. @ MySQL (the best combination with PHP) _ query ($ query, $ dbconnect );
  22. }
  23. @ MySQL (the best combination with PHP) _ query ("unlock tables", $ dbconnect );
  24. }
  25. Else {
  26. $ Cur_count = 1;
  27. $ Query = "insert into hit_count (hit_count) values ('$ cur_count ')";
  28. @ MySQL (the best combination with PHP) _ query ($ query, $ dbconnect );
  29. @ MySQL (the best combination with PHP) _ query ("unlock tables", $ dbconnect );
  30. }
  31. While (strlen ($ cur_count) <8)
  32. $ Cur_count = "0 $ cur_count ";
  33. $ Visit_time = date ("Y-m-d H: I: s ");
  34. $ Query = "insert into page_visit_record (visit_time, remote_addr, visit_page) values ('$ visit_time', '$ REMOTE_ADDR', '$ page ')";
  35. @ MySQL (the best combination with PHP) _ query ($ query, $ dbconnect );
  36. Header ("Content-type: image/gif ");
  37. $ Im = imagecreate (56,16 );
  38. $ Black = ImageColorAllocate ($ im, 0, 0 );
  39. $ Blue = ImageColorAllocate ($ im, 255 );
  40. $ White = ImageColorAllocate ($ im, 255,255,255 );
  41. $ Yellow = ImageColorAllocate ($ im, 255,255, 0 );
  42. Imagerectangle ($ im, 0, 0, 54, 14, $ blue );
  43. // Imagestring ($ im, 2, 4, 1, $ cur_count, $ yellow );
  44. Imagestring ($ im, 2, 4, 1, $ cur_count, $ yellow );
  45. ImageGif ($ im );
  46. ImageDestroy ($ im );
  47. ?>

The above content is an introduction to the support of MySQL and GD for simple graphic counters. I hope you will have some gains.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.