Hello I have this voting script attached it counts votes by IP address. Please how can I create a kind of time session on the IP addresses. \"say 5 votes a day per IP.
Consider the following... wherein I attempt to execute the same query over and over, at approximately 2-3 second intervals.
DROP TABLE IF EXISTS my_table;
CREATE TABLE my_table
(dt DATETIME NOT NULL);
SELECT * FROM my_table;
+---------------------+
| dt |
+---------------------+
| 2016-03-28 22:35:57 |
| 2016-03-28 22:36:06 |
+---------------------+
2 rows in set (0.00 sec)
mysql> INSERT INTO my_table (dt) SELECT DISTINCT NOW() FROM (SELECT 1) a LEFT JOIN my_table b ON NOW() < b.dt + INTERVAL 10 SECOND WHERE b.dt IS NULL;
Query OK, 1 row affected (0.00 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> SELECT * FROM my_table;
+---------------------+
| dt |
+---------------------+
| 2016-03-28 22:35:57 |
| 2016-03-28 22:36:06 |
| 2016-03-28 22:37:27 |
+---------------------+
3 rows in set (0.00 sec)
mysql> INSERT INTO my_table (dt) SELECT DISTINCT NOW() FROM (SELECT 1) a LEFT JOIN my_table b ON NOW() < b.dt + INTERVAL 10 SECOND WHERE b.dt IS NULL;
Query OK, 0 rows affected (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> SELECT * FROM my_table;
+---------------------+
| dt |
+---------------------+
| 2016-03-28 22:35:57 |
| 2016-03-28 22:36:06 |
| 2016-03-28 22:37:27 |
+---------------------+
3 rows in set (0.00 sec)
mysql> INSERT INTO my_table (dt) SELECT DISTINCT NOW() FROM (SELECT 1) a LEFT JOIN my_table b ON NOW() < b.dt + INTERVAL 10 SECOND WHERE b.dt IS NULL;
Query OK, 0 rows affected (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> SELECT * FROM my_table;
+---------------------+
| dt |
+---------------------+
| 2016-03-28 22:35:57 |
| 2016-03-28 22:36:06 |
| 2016-03-28 22:37:27 |
+---------------------+
3 rows in set (0.00 sec)
mysql> INSERT INTO my_table (dt) SELECT DISTINCT NOW() FROM (SELECT 1) a LEFT JOIN my_table b ON NOW() < b.dt + INTERVAL 10 SECOND WHERE b.dt IS NULL;
Query OK, 1 row affected (0.00 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> SELECT * FROM my_table;
+---------------------+
| dt |
+---------------------+
| 2016-03-28 22:35:57 |
| 2016-03-28 22:36:06 |
| 2016-03-28 22:37:27 |
| 2016-03-28 22:37:37 |
+---------------------+
4 rows in set (0.00 sec)
mysql> INSERT INTO my_table (dt) SELECT DISTINCT NOW() FROM (SELECT 1) a LEFT JOIN my_table b ON NOW() < b.dt + INTERVAL 10 SECOND WHERE b.dt IS NULL;
Query OK, 0 rows affected (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> SELECT * FROM my_table;
+---------------------+
| dt |
+---------------------+
| 2016-03-28 22:35:57 |
| 2016-03-28 22:36:06 |
| 2016-03-28 22:37:27 |
| 2016-03-28 22:37:37 |
+---------------------+
4 rows in set (0.00 sec)
mysql> INSERT INTO my_table (dt) SELECT DISTINCT NOW() FROM (SELECT 1) a LEFT JOIN my_table b ON NOW() < b.dt + INTERVAL 10 SECOND WHERE b.dt IS NULL;
Query OK, 0 rows affected (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> SELECT * FROM my_table;
+---------------------+
| dt |
+---------------------+
| 2016-03-28 22:35:57 |
| 2016-03-28 22:36:06 |
| 2016-03-28 22:37:27 |
| 2016-03-28 22:37:37 |
+---------------------+
4 rows in set (0.00 sec)
mysql> INSERT INTO my_table (dt) SELECT DISTINCT NOW() FROM (SELECT 1) a LEFT JOIN my_table b ON NOW() < b.dt + INTERVAL 10 SECOND WHERE b.dt IS NULL;
Query OK, 1 row affected (0.00 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> SELECT * FROM my_table;
+---------------------+
| dt |
+---------------------+
| 2016-03-28 22:35:57 |
| 2016-03-28 22:36:06 |
| 2016-03-28 22:37:27 |
| 2016-03-28 22:37:37 |
| 2016-03-28 22:37:47 |
+---------------------+
5 rows in set (0.00 sec)
mysql>