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' 

PHP - Header redirect issue Occur in Live Server

Method I

<?php ob_start(); if(isset($_GET['elimina_id'])){ if (in_array($_GET['elimina_id'], $_SESSION['cart']) ) { $index = (array_keys($_SESSION['cart'], $_GET['elimina_id'])); $i = $index[0]; unset($_SESSION['cart'][$i]); header('location: cart.php'); } } ob_end_flush(); ?>

Method II

HTML: <meta http-equiv="refresh" content="0;url=http://www.site.com/cart.php"> JavaScript #1: <script>window.location = "http://www.site.com/cart.php";</script> JavaScript #2: <script>window.navigate("http://www.site.com/cart.php");</script>

Wednesday, 25 June 2014

Set Position of Bootstrap Modal Popup

@media screen and (min-width: 768px) {
    .modal-dialog {
        left: 50%;
        right: auto;
        width: 624px;
    }
}
.modal-dialog{
position: absolute;
left: 50%;
//now you must set a margin left under zero - value is a half width your window
margin-left: -312px;
// this same situation is with height - example
height: 500px;
top: 50%;
margin-top: -250px;
} 

Alphanumeric Validation

Enter text filed only to allow alphabit & Numbers 
function alpha_numeric_validation(arg){
 var valReg = /^[A-Za-z0-9]+$/;
 if(valReg.test( arg ) ) {
  return false;
 } else {
  return true;
 }
}

Alpha Space Validation in JS

Enter text file allow allphabi & space only
function alpha_space_validation(arg){
 var valReg = /^[A-Za-z ]+$/;
 if(valReg.test( arg ) ) {
  return false;
 } else {
  return true;
 }
}

Email Validation - Form field Validate Email Address

alert(email_validation("asasas"))
function email_validation(arg){
 var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
 if( !emailReg.test( arg ) ) {
  return false;
 } else {
  return true;
 }
}

PHP number format 4 digits [duplicate]

Method I

echo str_pad( "3", 4, "0", STR_PAD_LEFT );
Input $s_number = "3"; Output: 0003

Method II

$s_number = '12';
printf("%04d", $s_number);
Input $s_number = "12"; Output: 0012

Tuesday, 24 June 2014

How to get Enum Values in Mysql?


function get_enum($table,$clname){
  $Query="SHOW COLUMNS FROM `$table` LIKE '$clname'";
  $result = $this->db->query($Query) or die("Get Enum value Query");
  if($result){
    $row = mysql_fetch_array( $result , MYSQL_NUM );
    $regex = "/'(.*?)'/";
    preg_match_all( $regex , $row[1], $enum_array );
    $enum_fields = $enum_array[1];
    return $enum_fields;
  }
  return false;
}

Saturday, 21 June 2014

Generate Password in alphanumeric using PHP


$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$password = substr( str_shuffle( $chars ), 0, $length );

Friday, 20 June 2014

Dynamically Date Range reset in jQuery UI date picker

Removes the datepicker functionality completely. This will return the element back to its pre-init state. 
Code :
$( "#start_date" ).datepicker( "destroy" );
$( "#end_date" ).datepicker( "destroy" );

How to get Json Edncoded value in js


var resp ="" //Json Value
var objJSON = eval("(function(){return " + resp + ";})()");
objJSON.name // Value

Thursday, 19 June 2014

HTML Special character and how to use that code


To do this... Type this... Or this... Description
   &lsquo; left single quote
   &rsquo; right single quote
   &sbquo; single low-9 quote
   &ldquo; left double quote
   &rdquo; right double quote
   &bdquo; double low-9 quote
   &dagger; dagger
   &Dagger; double dagger
   &permil; per mill sign
   &lsaquo; single left-pointing angle quote
   &rsaquo; single right-pointing angle quote
   &spades; black spade suit
   &clubs; black club suit
   &hearts; black heart suit
   &diams; black diamond suit
   &#9733; black star
   &#9734; white star
   &oline; overline, = spacing overscore
   &larr; leftward arrow
   &uarr; upward arrow
   &rarr; rightward arrow
   &darr; downward arrow
©   &copy; &#169; copyright sign
   &trade; trademark sign
&#00;-
&#08;
unused
&#09; horizontal tab
&#10; line feed
  &nbsp; &#160; Non-breaking space
&#32; space
!   &#33; exclamation mark
"   &quot; &#34; double quotation mark
#   &#35; number sign
$   &#36; dollar sign
%   &#37; percent sign
&   &amp; &#38; ampersand
'   &#39; apostrophe
(   &#40; left parenthesis
)   &#41; right parenthesis
*   &#42; asterisk
+   &#43; plus sign
,   &#44; comma
-   &#45; hyphen
.   &#46; period
·   &middot; &#183; middle dot
   &#149; bullet
/   &frasl; &#47; slash
0 - 9 &#48;-
&#57;
digits 0-9
:   &#58; colon
;   &#59; semicolon
<   &lt; &#60; less-than sign
=   &#61; equals sign
>   &gt; &#62; greater-than sign
?   &#63; question mark
@   &#64; at sign
A - Z &#65;-
&#90;
uppercase letters A-Z
[   &#91; left square bracket
\   &#92; backslash
]   &#93; right square bracket
^   &#94; caret
_   &#95; horizontal bar (underscore)
`   &#96; grave accent
a - z &#97;-
&#122;
lowercase letters a-z
{   &#123; left curly brace
|   &#124; vertical bar
/   &frasl; &#47; slash
°   &deg; &#176; degree sign
±   &plusmn; &#177; plus or minus
²   &sup2; &#178; superscript two
³   &sup3; &#179; superscript three
´   &acute; &#180; acute accent
µ   &micro; &#181; micro sign
   &para; &#182; paragraph sign
¸   &cedil; &#184; cedilla
¹   &sup1; &#185; superscript one
º   &ordm; &#186; masculine ordinal
   &raquo; &#187; right angle quote
¼   &frac14; &#188; one-fourth
½   &frac12; &#189; one-half
¾   &frac34; &#190; three-fourths
¿   &iquest; &#191; inverted question mark
À   &Agrave; &#192; uppercase A, grave accent
Á   &Aacute; &#193; uppercase A, acute accent
   &Acirc; &#194; uppercase A, circumflex accent
à  &Atilde; &#195; uppercase A, tilde
Ä   &Auml; &#196; uppercase A, umlaut
Å   &Aring; &#197; uppercase A, ring
Æ   &AElig; &#198; uppercase AE
Ç   &Ccedil; &#199; uppercase C, cedilla
È   &Egrave; &#200; uppercase E, grave accent
É   &Eacute; &#201; uppercase E, acute accent
Ê   &Ecirc; &#202; uppercase E, circumflex accent
Ë   &Euml; &#203; uppercase E, umlaut
Ì   &Igrave; &#204; uppercase I, grave accent
Í   &Iacute; &#205; uppercase I, acute accent
Π  &Icirc; &#206; uppercase I, circumflex accent
Ï   &Iuml; &#207; uppercase I, umlaut
Р  &ETH; &#208; uppercase Eth, Icelandic
Ñ   &Ntilde; &#209; uppercase N, tilde
Ò   &Ograve; &#210; uppercase O, grave accent
Ó   &Oacute; &#211; uppercase O, acute accent
Ô   &Ocirc; &#212; uppercase O, circumflex accent
Õ   &Otilde; &#213; uppercase O, tilde
Ö   &Ouml; &#214; uppercase O, umlaut
×   &times; &#215; multiplication sign
Ø   &Oslash; &#216; uppercase O, slash
Ù   &Ugrave; &#217; uppercase U, grave accent
Ú   &Uacute; &#218; uppercase U, acute accent
Û   &Ucirc; &#219; uppercase U, circumflex accent
Ü   &Uuml; &#220; uppercase U, umlaut
Ý   &Yacute; &#221; uppercase Y, acute accent
Þ   &THORN; &#222; uppercase THORN, Icelandic
ß   &szlig; &#223; lowercase sharps, German
à   &agrave; &#224; lowercase a, grave accent
á   &aacute; &#225; lowercase a, acute accent
â   &acirc; &#226; lowercase a, circumflex accent
ã   &atilde; &#227; lowercase a, tilde
ä   &auml; &#228; lowercase a, umlaut
å   &aring; &#229; lowercase a, ring
æ   &aelig; &#230; lowercase ae
ç   &ccedil; &#231; lowercase c, cedilla
è   &egrave; &#232; lowercase e, grave accent
é   &eacute; &#233; lowercase e, acute accent
ê   &ecirc; &#234; lowercase e, circumflex accent
ë   &euml; &#235; lowercase e, umlaut
ì   &igrave; &#236; lowercase i, grave accent
í   &iacute; &#237; lowercase i, acute accent
î   &icirc; &#238; lowercase i, circumflex accent
ï   &iuml; &#239; lowercase i, umlaut
ð   &eth; &#240; lowercase eth, Icelandic
ñ   &ntilde; &#241; lowercase n, tilde
ò   &ograve; &#242; lowercase o, grave accent
ó   &oacute; &#243; lowercase o, acute accent
ô   &ocirc; &#244; lowercase o, circumflex accent
õ   &otilde; &#245; lowercase o, tilde
ö   &ouml; &#246; lowercase o, umlaut
÷   &divide; &#247; division sign
ø   &oslash; &#248; lowercase o, slash
ù   &ugrave; &#249; lowercase u, grave accent
ú   &uacute; &#250; lowercase u, acute accent
û   &ucirc; &#251; lowercase u, circumflex accent
ü   &uuml; &#252; lowercase u, umlaut
ý   &yacute; &#253; lowercase y, acute accent
þ   &thorn; &#254; lowercase thorn, Icelandic
ÿ   &yuml; &#255; lowercase y, umlaut

jQuery Date picker ui select date range picker

Jquery UI Datepicker select date range between Two days
$( "#start_date" ).datepicker({
   minDate: new Datenew Date(1999, 10 - 1, 25),
   maxDate: new Datenew Date(1999, 10 - 1, 30),
   defaultDate: "+1w",
   changeMonth: true,
   numberOfMonths: 2,
   onClose: function( selectedDate ) {
      $( "#end_date" ).datepicker( "option", "minDate", selectedDate );
   }
});

$( "#end_date" ).datepicker({
   minDate: new Datenew Date(1999, 10 - 1, 25),
   maxDate: new Datenew Date(1999, 10 - 1, 30),
   defaultDate: "+1w",
   changeMonth: true,
   numberOfMonths: 2,
   onClose: function( selectedDate ) {
      $( "#start_date" ).datepicker( "option", "maxDate", selectedDate );
   }
});

Wednesday, 18 June 2014

Enter Integrr Number only


Enter Integer only in text fileds
onkeyup="if (/\D/g.test(this.value)) this.value = this.value.replace(/\D/g,'')"

Thursday, 12 June 2014

How to Get a Google Adsense Account Approval

1. Create a Blog or a website.
2. Upload genuine content
3. Upload more and more relevant content
4. Submit your web page URL to search engines
5. Create an account with Google Analytics and Google webmasters
6. Link your websites with the Analytics and Webmasters account
7. Optimize your web page
8. Ensure the Quality of the content of your web site
9. Wait for at least 6 months and during that time increase the traffic to your web site.
10. Once you have completed the above steps and satisfied them, Now apply for a Google AdSense account.