Tag: PHP

Generate random number in PHP

In PHP, you can generate a random number between 1 and 9 using the rand() or mt_rand() functions. Here are examples of both: Using rand() Function: $randomNumber = rand(1, 9);echo “Random number between 1 and 9: ” . $randomNumber; Using mt_rand() Function: $randomNumber = mt_rand(1, 9);echo “Random number between 1 and 9: ” . $randomNumber; […]

Read More

Convert Indian currency from numeric to words in PHP

To convert a numeric value to Indian currency format (words), you can use a custom function. Here’s an example of how you can achieve this: This function convertToIndianCurrencyWords() converts a numeric value into its Indian currency format representation in words. Adjust the code as needed for different ranges or specific formatting requirements. The example provided here is […]

Read More

Covert all date data format from VARCHAR to DATE in any MySQL table

Converting varchar data to date format in MySQL involves several steps. Here’s a method to achieve this: Assuming your varchar date column is named date_column and your table is named your_table, you can follow these steps: Remember to take a backup of your data before making such changes to your database. Incorrectly manipulating your database […]

Read More

Export MySQL data into Excel using PHP

To fetch data from a MySQL database and export it to Excel, you can use PHP along with a library like PHPExcel or PHPSpreadsheet (which is the successor of PHPExcel). Here, I’ll provide an example using PHPExcel. Please note that PHPExcel is now deprecated, and PHPSpreadsheet is recommended for new projects. If you’re starting a […]

Read More

How to reverse date in PHP

To reverse the date from the format “yyyy-mm-dd” to “mm-dd-yyyy” in PHP, you can use the following script: In this script, the variable $date holds the original date in the “yyyy-mm-dd” format. The date() function is then used to convert and format the date. By passing the $date variable to strtotime(), it is converted to […]

Read More