MySQL monthly Sale of last 12 months including months with no Sale

SELECT DATE_FORMAT(date, "%b") AS month, SUM(total_price) as total FROM cart WHERE date <= NOW() and date >= Date_add(Now(),interval – 12 month) GROUP BY DATE_FORMAT(date, "%m-%Y") This query displaying result for only existing month. I need all 12 months sales. Output: "month" "total" ————– "Jun" "22" "Aug" "30" "Oct" "19" "Nov" "123" "Dec" "410" Required Output: … Read more

PHP prepend leading zero before single digit number, on-the-fly

PHP – Is there a quick, on-the-fly method to test for a single character string, then prepend a leading zero? Example: $year = 11; $month = 4; $stamp = $year.add_single_zero_if_needed($month); // Imaginary function echo $stamp; // 1104 Answers: Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not … Read more