Tag: PHP

Fetch data from Google Sheet and show in HTML using PHP

This documentation explains how to use the provided PHP code to fetch data from Google Sheets and display it in a custom layout using HTML/CSS. Setup Instructions Step 1: Get Your Google Sheet ID Open your Google Sheet in a web browserLook at the URL in the address bar – it will look like:https://docs.google.com/spreadsheets/d/BmzaSyBzQ0cRTrbf_vxrB75nh8AoV3BtawPiiCQ/edit#gid=0The long […]

Read More

Block HTtrack or any other web scrapper

There are several web scrappers tools are available by which your website can be do nloaded as static files. The simplest way to block these web scrap ers is to add the following blocking bots code in your website .htaccess file.

Read More

PHP script to download file from specific folder

Below is a simple example of a PHP script that allows you to download file from a specific folder. You can link to this PHP file with the file name as a parameter.Create a file named download.php and add the following code: Replace ‘/path/to/your/files/’ with the actual path to the folder where your files are […]

Read More

Get total of MySQL column and show highest totals

To get the total of a MySQL field and then select the three highest totals from the table, you can use the following PHP script: Make sure to replace ‘your_username’, ‘your_password’, ‘your_database_name’, ‘field_name’, and ‘table_name’ with the actual values for your MySQL configuration and table structure. In this script, the SQL query uses the SUM […]

Read More

Print total of a variable inside while loop outside of the loop

To accumulate values from a MySQL query inside a while loop and then calculate the total value outside the loop, you can use a variable to store the total value while iterating through the records. Here’s anexample in PHP: This PHP script fetches records from the database, accumulates the values from a specific column (value_column), […]

Read More

Import CSV data into MySQL using PHP

Here’s a detailed example of how to import data from a CSV file into a MySQL database using PHP. The script processes each row one by one, displays a success message for each successfully inserted row, and stops the process if any error occurs, showing the error message. Prerequisites: Ensure you have a MySQL database […]

Read More

PHP function to get difference between dates

Below is a PHP function that calculates and displays the difference in days between two dates. This function will take two date strings as inputs, convert them to DateTime objects, and then calculate the difference in days. Here’s how you can define and use the function: Explanation: Creating DateTime Objects: new DateTime($date1): This converts the […]

Read More