Would you like to do the counting on a user-only IDS query?
Yes, you can count how many uploads the user has made. Just use COUNT
and group by id
. Example:
SELECT 'id', COUNT('id') AS total FROM 'uploads' GROUP BY 'id'
Here it will group all users by ID
and then count how many records that ID
clustered have.
And to filter by date, just use the BETWEEN operator. . With this operator you can pass the start date and end date. Example:
"SELECT 'id', COUNT('id') AS total FROM 'uploads' WHERE 'date_added' BETWEEN '2018-02-20 00:00:00' AND '2018-02-22 00:00:00' GROUP BY 'ID'"
Here he will also count the number of uploads per user, but now he will filter between the dates indicated.
If there is one, what would be the best method to use php to count users or perform mysql?
You can do this through PHP yes, both with MySQLI and
Example with PDO :
<?php
$conn = new PDO("mysql:dbname=NOME-DO-BANCO-DE-DADOS;host=localhost", "DB-USUARIO", "DB-SENHA");
$stmt = $conn->prepare("SELECT 'id', COUNT('id') AS total FROM 'uploads' WHERE 'date_added' BETWEEN '2018-02-20 00:00:00' AND '2018-02-22 00:00:00' GROUP BY 'ID'");
$stmt->execute();
var_dump( $stmt->fetchAll() );
Example with MySQLi :
<?php
$conn = new MySQLi("localhost", "DB-USUARIO", "DB-SENHA", "NOME-DO-BANCO-DE-DADOS");
$result = $conn->query("SELECT 'id', COUNT('id') AS total FROM 'uploads' WHERE 'date_added' BETWEEN '2018-02-20 00:00:00' AND '2018-02-22 00:00:00' GROUP BY 'ID'");
while ($row = $result->fetch_assoc()) {
var_dump( $row );
}
Structure used in the example:
+------------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+------------------+------+-----+---------+-------+
| id | int(11) | NO | | NULL | |
| file_id | int(10) unsigned | NO | | NULL | |
| date_added | datetime | NO | | NULL | |
+------------+------------------+------+-----+---------+-------+
Demo