If you like DNray Forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...

 

DB Request for withdrawal calculation from a certain date

Started by brandsmith, Sep 10, 2022, 12:53 AM

Previous topic - Next topic

brandsmithTopic starter

Greetings! I am looking for a way to retrieve the total value of a person's replenishments from a table in phpmyadmin. Specifically, I need a code that can extract values from a single table based on a specific date, which is 1658966420. Moreover, I aim to calculate the sum of these values and display the result.

To achieve this, I wonder if there is a method to filter the variables retrieved from the database and limit them only to those with dates greater than 1658966420?
  •  

amomswish

Phpmyadmin does not contain any tables or values, but rather displays content from the MySQL database. This is similar to how a forum is not housed within a browser, but instead is stored on a server and accessed via requests made by the browser.

In order to make a successful request, adequate introductory information is required. Without it, neither users nor psychics can provide the necessary context. As an example, consider the following code snippet which reduces the current server time by one day and then retrieves data for a specific user, filtering by time and limiting the output to 50 results:

$time = date("Y-m-d", time());
$d=date('Y-m-d H:i:s');
$time = new date-time($d);
#reducing the current server time by one day
$time->change("-1 day");
$time = $time->format('Y-m-d H:i:s');
$login= "test";
$query="SELECT * FROM users, WHERE login = '$login' AND time>'$time' ORDER BY time Time limit 50";
  •  

spyindiaanu

Yes, you can achieve this using PHP and MySQL query. Here's an example code that demonstrates how to retrieve the total value of a person's replenishments from a table based on a specific date in phpmyadmin:

```php
<?php

// Set up connection parameters for MySQL
$servername = "localhost";
$username = "your_username";
$password = "your_password";
$database = "your_database";

// Create connection
$conn = new mysqli($servername, $username, $password, $database);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Specify the date you want to filter
$filterDate = 1658966420;

// Query to retrieve values greater than the specified date and calculate the sum
$sql = "SELECT SUM(value) AS total_value FROM your_table WHERE date > $filterDate";

$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // Fetch the result as an associative array
    $row = $result->fetch_assoc();
   
    // Retrieve the total_value
    $totalValue = $row["total_value"];
   
    // Display the result
    echo "Total value of replenishments after ".$filterDate." is: ".$totalValue;
} else {
    echo "No results found.";
}

// Close the connection
$conn->close();

?>
```

Make sure to replace "your_username", "your_password", "your_database", "your_table" with your actual credentials and table name. This code connects to the MySQL database, executes the query to retrieve the sum of the values greater than the specified date, and then displays the result.


Here's an expanded version of the code with some additional explanations:

```php
<?php

// Set up connection parameters for MySQL
$servername = "localhost";
$username = "your_username";
$password = "your_password";
$database = "your_database";

// Create connection
$conn = new mysqli($servername, $username, $password, $database);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Specify the date you want to filter
$filterDate = 1658966420;

// Query to retrieve values greater than the specified date and calculate the sum
$sql = "SELECT SUM(value) AS total_value FROM your_table WHERE date > $filterDate";

$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // Fetch the result as an associative array
    $row = $result->fetch_assoc();
   
    // Retrieve the total_value
    $totalValue = $row["total_value"];
   
    // Display the result
    echo "Total value of replenishments after ".$filterDate." is: ".$totalValue;
} else {
    echo "No results found.";
}

// Close the connection
$conn->close();

?>
```

In this code, we first set up the connection parameters for MySQL, such as the server name, username, password, and database name. Then, we create a connection to the database using the `mysqli` class.

Next, we specify the date you want to filter in the `$filterDate` variable. This value should be a Unix timestamp representing the specific date you want to filter.

We then construct the SQL query string to retrieve the sum of the `value` column from the `your_table` table, where the `date` column is greater than the specified `$filterDate`.

After executing the query using the `query()` method of the connection, we check if the result has any rows using the `num_rows` property. If there are rows, we fetch the result as an associative array using the `fetch_assoc()` method.

We retrieve the total value from the associative array using the key `"total_value"`, and store it in the `$totalValue` variable.

Finally, we display the result by echoing a message that includes the filter date and the total value. If no results are found, we display a "No results found." message.

Remember to replace the placeholder values with your actual credentials and table name before running this code.
  •  


If you like DNray forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...