Percentages for files sent via form

Asked

Viewed 82 times

0

I have a contact form (PHP) for each user, and through each form it is possible to send files (doc. and pdf) and goes directly to the user.

So far everything works great, but I need to know the percentage of files sent to each user, and I don’t know how to get there. Someone can shine a light on me?

  • It would not be possible to save the files in a database and then pull the number of rows each user (column) would have ?

  • But that’s gonna overload the database, we’re talking about a database of over a thousand files, and I want to store the data graphically, so I can access it whenever necessary. So I can keep users up to date.

  • Basically you want an upload system with progress bar, right?

  • @I open my goal is to know the percentage of files sent through a form (I already have) to the user X. To be aware which user has the most files received.

1 answer

1


Based in that comment that best clarified the goal to be achieved, I leave as reference this other answer, also mine.


Your problem seems to be more about mathematical logic than about the implementation itself. It’s simple, just cross-multiplication.

Based on the answer left as reference, we have the logic:

A --- B
C --- D

Putting the sketch above in a mathematical formula, we have:

D = BC / A

Being:

  • To the total of files sent
  • B the total percentage (always 100)
  • C the total of files sent per user
  • D the value of the equation you need to discover

Assuming in a month 500 files have been uploaded and User X sent 337, we have:

D = ( 100 * 337 ) / 500
D = 33700 / 500
D = 67,4%

That is to say, 67.4% of all files uploaded to the website.

The second part of your problem, also covered in stack reference is to perform this in batch, through a user function.

However, unlike the above scenario you may not want to display this percentage individually, so in this case, you create a matrix with all the percentages and then the ordains. Would something like this:

$percentual = array();

while( /** Faz a leitura do recurso vindo do banco */ ) {

    $percentual[ $userID ] = getPercentage( $userUploads, $filesUploaded )
}

sort( $percentuals);

print_r( $percentuals );

function getPercentage( $total, $uploads ) {
    return round( ( 100 * $uploads ) / $total );
}

Deleted the way the resource is read in order to vary according to the DBMS and the useful connection method

In the above example:

  • $userid is the user ID, but you can replace, perhaps, with the user name and have an associative array ready for display.
  • $userUploads is the total of files sent by the user. It may come from a COUNT() used in your SQL
  • $filesUploaded is the total of uploads made. It can come from a previously executed query or by summing each COUNT above. In this case, however, it may be necessary to break the routine in two loops.

The way out could be something like:

Array (

  [X] => 67.4
  [Y] => 16.3
  [Z] => 16.3
)

That is, the user X was responsible for 67.4% of shipments while users Y and Z only 16.3%

  • This is exactly what I was looking for. What I was missing was the logic, and the implementation part. However, I will have to make individual data for each user to send them. According to the X number of posts had X number of files sent. But with this path you indicated me I can get there.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.