Count how many times a file was downloaded in PHP

Tags: php mysql count

I am building a website and I have a button which allows an user to download a file.

Here is how my table in phpmyadmin looks like:

enter image description here

And here is my code that allows an user to download a file:

<a href="data/<?php echo $date['name']; ?>" download><input type="submit" name="submit" value="Prenesi"></a>

How can I store a number of times the button was clicked in my MySQL table? I only found a topic where somebody wanted to store a number of downloads in TXT file, but I don't want to do that.

Thank you for your help! :)


For to catch request you can use GET or POST form methods. Simple example:

<form action="" method="POST">
    <a href="data/<?php echo $date['name']; ?>" download>
        <input type="submit" name="submit" value="Prenesi">

    if($_POST["submit"]) {
        // database connection and update code
        // update TABLE set downloaded = downloaded + 1 where id = VALUE
        echo 'Updated download count';

I think it should be enough to check for blank spaces and if a cell is blank, do not delete that row. Like this

Sub DeleteRows()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim i As Long
For i = Range("E" & Rows.Count).End(xlUp).Row To 1 Step -1
    If (Range("E" & i).Value > -5 And Range("E" & i).Value < 5 and Range("E" & i) <> "") Then
         Range("E" & i).EntireRow.Delete
        If (Range("D" & i).Value > -500 And Range("D" & i).Value < 500 and Range("D" & i) <> "") Then
            Range("D" & i).EntireRow.Delete
        End If
    End If
Next i
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub

Because your assumption is wrong. You expect new Vector3(0,0,0) and new Vector3(Screen.width, 0, 0) to be in screen space (left & right edge of screen I believe) but in fact they are in world space (Vector3(0,0,0) is the world's origin, not the edge of screen).

You can try this. Basically, this code moves your object to where you tap.

void OnMouseUp()
    // Cast a ray from camera through mouse position
    Ray ray = camera.ScreenPointToRay(Input.mousePosition);
    RaycastHit hitInfo;
    Physics.Raycast(ray, out hitInfo);
    // Lerp to the impact point
    transform.position = Vector3.Lerp(transform.position, hitInfo.point, 2f * Time.deltaTime);
By : Loop

This video can help you solving your question :)
By: admin