Monday, 30 June 2014

MySQL IF function

MySQL IF function
Syntax: IF(expr,if_true_expr,if_false_expr)
Example:
SELECT IF(1 = 2,'true','false'); -- false
SELECT IF(1 = 1,' true','false'); -- true

MySQL Query GROUP BY day / month / year

Method I :
SELECT count('id') as cnt,order_status,order_date FROM `product_order` 
group by MONTH(order_date) 
Method II :
SELECT count('id') as cnt,order_status,order_date FROM `product_order` 
group by DATE_FORMAT(order_date, '%m')
Method III:
SELECT SQL_NO_CACHE YEAR(record_date), MONTH(record_date), COUNT(*) FROM stats 
GROUP BY YEAR(record_date)*100 + MONTH(record_date)

SELECT YEAR(date_column), MONTH(date_column), COUNT(*)
FROM date_table
GROUP BY DATE_FORMAT(date_column, '%Y%m')

Google Maps Image APIs

Get Google Map Image for specific latittude & longitude
Static Maps API

<img src="http://maps.google.com/staticmap?size=500x400&markers=11,78&zoom=12">


<img src="http://maps.googleapis.com/maps/api/streetview?size=200x200&location=40.720032,-73.988354&heading=235">

Saturday, 28 June 2014

How to generate passoword in php with specific length?

function generate_password( $length = 8 ) {
  $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  $password = substr( str_shuffle( $chars ), 0, $length );
  return $password;
 }

How to get n digit random numers in php?

function generate_number_code( $length = 8 ) {
  $chars = "0123456789";
  $password = substr( str_shuffle( $chars ), 0, $length );
  return $password;
 }

JS get random Numbers

function getRandom(length) {
 var rand = Math.floor(Math.pow(10, length-1) + Math.random() * 9 * Math.pow(10, length-1));
 return rand;
}

PHP - Mysql Get date between two date ranges

Fetching records between two date ranges
Between two years
SELECT * FROM `dt_tb` WHERE year( dt2 ) between 2004 and 2005
Between two month ranges. 
SELECT * FROM `dt_tb` WHERE month(dt) between '02' and '08'

SELECT * FROM `dt_tb` WHERE month(dt) between '02' and '08' and year(dt) between 2004 and 2005

Between two date ranges
SELECT * FROM `dt_tb` WHERE dt BETWEEN '2005-01-01' AND '2005-12-31' 

Feet/Inches to Meters Converter & Lbs to Kgs Converter

 <!DOCTYPE html> <html lang="en"> <head>   <meta charset="UTF-8" />   <title>Feet/Inches ⇄...