Posts

Showing posts from 2012

updating two tables in a single query in mysql

updating two tables in a single query in mysql UPDATE  tb1 , tb2  SET  tb1.name= 'new name', tb2.name = 'tb2 name'   WHERE   tb1.id = '1'  AND  tb2.id = '5'

delete data from two tables at the same time in mysql

delete record from two table in same time in mysql  it is useful when we create two related table in mysql     // with inner join  DELETE tb1, tb2 FROM tb1 inner JOIN tb2  WHERE tb1.id=tb2.tb1id and tb1.id=1  // with left or Right Join  DELETE tb1, tb2 FROM tb1 LEFT JOIN tb2 ON tb1.id=tb2.tb1id  WHERE tb1.id=1

php call function within same class

<?php  class  a {  public  function  f1 (){ echo  'this is a:f1 function' ;   }    function  f3 (){   a :: f1 (); // call here same class method  echo  '<br>Call here f1 function ' ;  } } class  b { function  f2 (){  a :: f3 (); echo  '<br> This is b:f2 function' ; } } $ob = new  b ();  $ob -> f2 (); ?> OutPut: this is a:f1 function Call here f1 function  This is b:f2 function

how to call one class method from another in php

<?php class  a { public  function  f1 (){ echo  'this is a:f1 function' ;   }   } class  b { function  f2 (){    a :: f1 ();  // claa here method of another class in php   echo  '<br> This is b:f2 function' ; } } $ob = new  b (); $ob -> f2 ();  ?> OutPut: this is a:f1 function This is b:f2 function

group_concat in mysql example

group_concat in mysql example CITY_ID CITY_NAME STATE_NAME 1 Bhopal MP 2 Indore MP 3 Delhi DELHI 4 Allahabad UP SELECT group_concat(concat(`city_id`,'@@', `city_name`,'@@', `state_name`),'###') as city FROM `city` Result 1@@Bhopal@@MP###,2@@Indore@@MP###,3@@Delhi@@DELHI###,4@@Allahabad@@UP###

date between two date in php

<?php   // check datebetween two dates  function  chkbetweendate ( $chkdate = '' , $startdate = '' , $enddate = '' ){  $chkdate = strtotime ( $chkdate ); $startdate = strtotime ( $startdate ); $enddate = strtotime ( $enddate );  if( $startdate  <=  $chkdate  &&  $chkdate  <=  $enddate ){ return  true ; }else { return  false ; } }         // call function here      if( chkbetweendate ( '2012-10-10' , '2012-10-5' , '2012-10-15' )){  echo  "2012-10-10 between date" ;  } else {  echo  "2012-10-10 not in between date" ;  }

Create Query for all table in mysql

1 . create query for change all tables to innodb  ENGINE in   mysql SELECT CONCAT('ALTER TABLE ', table_name, ' ENGINE=InnoDB;') as ExecuteTheseSQLCommands FROM information_schema.tables WHERE table_schema = 'database_name' ORDER BY table_name DESC; 2 . create query for  TRUNCATE TABLE  all database table SELECT CONCAT('TRUNCATE TABLE ', table_name, ';') FROM INFORMATION_SCHEMA.tables WHERE table_schema = 'database_name'

export in mysql

1.  export in mysql in txt file  SELECT * FROM  MyTable INTO OUTFILE  'C:\\FileName.txt'  2.   export in mysql in csv file  SELECT * FROM table1  INTO OUTFILE 'c:///mytable.csv' FIELDS ESCAPED BY '""' TERMINATED  BY ','  ENCLOSED BY '"' LINES TERMINATED BY '\r\n'  3. .  export in mysql in excel file

php multidimensional array to single dimension array

<?php  php convert multidimensional array to single dimension array convert multidimensional array to single array php function  multidimensional_array_to_single_dimension_array ( $array ) {     if (! $array ) return  false ;     $flat  = array();     $iterator   = new  RecursiveIteratorIterator (new  RecursiveArrayIterator ( $array ));       foreach ( $iterator  as  $value )  $singhal [] =  $value ;    return  $singhal ; } $arr =array( 1 , 2 ,array( 4 , 5 ), 6 ,array( 7 , 8 ,array( 9 , 10 , 11 ,array( 12 , 13 , 14 ))));     print_r ( multidimensional_array_to_single_dimension_array ( $arr )); ?> OUTPUT: Array ( [0] => 1 [1] => 2 [2] => 4 [3] => 5 [4] => 6 [5] => 7 [6] => 8 [7] => 9 [8] => 10 [9] => 11 [10] => 12 [11] => 13 [12] =...

Regular Expression

Regular Expression in JavaScript Regular Expression in php Regular Expression in MySql 

transaction in mysql php

<?php  MYISAM Not Support Transaction  /* CREATE TABLE IF NOT EXISTS `table1` (   `id` int(11) NOT NULL auto_increment,   `name` varchar(250) NOT NULL,   `address` varchar(250) NOT NULL,   PRIMARY KEY  (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; */ $host  =  'localhost' ;  $user  =  'rajeev' ;  $password  =  'mypass' ; $db  =  'demo' ;  $con  =  mysql_connect ( $host ,  $user ,  $password ); mysql_select_db (  $db ); mysql_query ( "SET AUTOCOMMIT=0" ); mysql_query ( "START TRANSACTION" );     $query  =  "INSERT INTO table1 (name,address) values ('name','bhopal')" ;   $result  =  mysql_query ( $query );    if( $result ){ ...

Create New User In Mysql with permission

create new user in mysql database set user permissions mysql delete user permissions in mysql rajeev =User Name mypass = Password demo = database name   // create user CREATE USER ' rajeev '@'localhost' IDENTIFIED BY  ' mypass ' ;     // set permission  in demo database  GRANT SELECT, INSERT, DELETE ON   demo .* TO rajeev @'localhost' IDENTIFIED BY ' mypass ';  // set all permission in demo database GRANT ALL ON demo .* to ' rajeev '@'localhost';  // remove access permission from demo database REVOKE select, UPDATE, DELETE ON demo .*  FROM ' rajeev '@'localhost';   // remove all permission  REVOKE ALL PRIVILEGES, GRANT OPTION FROM ' rajeev '@'localhost';  // select user detail  from database  select * from mysql.user where User=' rajeev ';

Email Validation In PHP

Email address Validation in PHP    <form> Email Address: <input type='text' name='email'> <input type='submit' value='Submit'> </form>   <?php  $email = $_REQUEST [ 'email' ];    $expression  =  "^[a-z0-9_\+-]+(\.[a-z0-9_\+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,4})$" ;   if ( eregi ( $expression ,  $email )) {  echo  'Valid Email' ;   } else {   echo  'Invalid Email' ;  }   ?>

tooltip jquery example

tooltips jquery example tooltips jquery Demo

user already exits

This Code Is use for User name Already Exits or email id already exits  here this function call using Ajax Method  <?php  function  ckhuserid ( $udetail ){ $arr = explode ( "!@@@!" , $udetail );  if( $arr [ 1 ]== 'edit' ){ $val = executescalar ( "user" , "id" , "uname='" . $arr [ 0 ]. "' and id<>'" . $arr [ 2 ]. "' " ,  "" , "false" , "str" );  } else {  $val = executescalar ( "user" , "id" , "uname='" . $arr [ 0 ]. "'" ,  "" , "false" , "str" );  } if( $val != '' ){  // alresdy exist    echo  "yes" ; } }  ?>  // JavaScript Code <script>              function ckhuserid(x,cas,id){ // x=this; cas= case=registration or edit profile , id=user id on edit time  uname=$(x).val(); str=uname; if(cas=='edit'){ st...

Email Validation For Group Mail

Email Address: Example: Email1, Email2, Email3 etc function ckhmailaddress(){ var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; var allemail = $('#txtemail').val() ; var email = allemail.split(","); for(i=0 ; i< email.length ; i++){ if(emailPattern.test(email[i])==false){    alert('please Enter Valid Email Id');     document.getElementById('txtemail').focus();     return false ;    } } return true ;  }

contact us page

For Me   <?php  /***************** PHP Code **********************/  require_once( 'config/bootstrap.php' );  if(isset( $_POST ) && ( $_REQUEST [ "mode" ]== 'send' )){ $name  =  strip ( $_POST [ 'txtname' ]);  $email  =  strip ( $_POST [ 'txtemail' ]);  $ph  =  strip ( $_POST [ 'txtphone' ]); $msg  =  strip ( $_POST [ 'txtcomment' ]); $headers  =   "From: " . $email . "\r\n" ;  $headers  .=  'MIME-Version: 1.0'  .  "\r\n" ; $headers  .=  'Content-type: text/html; charset=iso-8859-1'  .  "\r\n" ; $headers  .=  "\r\nX-Mailer: PHP/"  .  phpversion (); $subject  =  "contact us: nethomes.com" ; $message  =  "Name: "  .  $name  . "<br> Phone No: "  .  $ph .  "<br/>Em...

add data without html editor

str_replace('&nbsp;',' ',strip_tags($_POST["txtcomment"]))

add more input box in html

Name   Designation   /**************** HTML Code **************************/ <tr> <td width="30%" align="right"  valign="top"> <label class="mylbl">  Contact person  &nbsp;</label></td> <td width="50%"  valign="top"> <table id="addmorecontact"> <tr> <td><label class="mylbl">  Name &nbsp;</label> </td> <td><label class="mylbl"> Designation &nbsp;</label> </td> <!-- <td>  </td>--> </tr> <tr id="inputbox0">     <td><input type="text" name="txtname[]" id="txtname0" style="width:200px" class="box " /> </td> <td> <input type="text" name="txtdesig[]" id="txtdesig0" style="width:185px...

how to upload image into database using php

how to upload file in database in php how to upload image into database using php step 1 1. create database demo CREATE TABLE IF NOT EXISTS `table1` (   `id` int(11) NOT NULL auto_increment,   `file` longblob NOT NULL COMMENT 'file in binary',   `type` varchar(250) NOT NULL,   `name` varchar(250) NOT NULL,   PRIMARY KEY  (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; 2. create two file  demo.php photo.php demo.php <?php  $con = mysql_connect ( 'localhost' , 'root' , '' ); mysql_select_db ( 'demo' , $con ); //print_r($_FILES); if(isset( $_REQUEST [ 'sub' ])){   $tpy = $_FILES [ 'txtfile' ][ 'type' ];    $name = $_FILES [ 'txtfile' ][ 'name' ];     $c = file_get_contents ( $_FILES [ 'txtfile' ][ "tmp_name" ]); mysql_query ( "insert into table1(file,type,name) values('" . addslashes ( $c ). "', '" . $tpy ....

dd-mm-yyyy in javascript

date format in javascript dd mm yyyy Chang date format in JavaScript function datef(x){ var arr = new Array(); arr=["","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]; arr2=x.split('-'); i=parseInt(arr2[1],10); d=arr2[2]+"-"+arr[i]+"-"+arr2[0]; return d; }

how to get past date in php

<?php // get past 15 days date  in php $d1 = date ( 'Y-m-d' ,  strtotime ( '-15 days' ));  date ( 'Y-m-d' ,  strtotime ( '-15 months' ));  // $d1 = date ( 'Y-m-d' ,  strtotime ( ' -20 year ' ));  // next 15 days date in php $d1=date('Y-m-d', strtotime('15 days'));  $date = "2012-10-10"; $newdate = strtotime ( ' -10 days ' , strtotime ( $date ) ) ; $newdate = date ( 'Y-m-d' , $newdate ); echo $newdate; ?>

how to execute php code in html

1. create   . htaccess   file and write code  RemoveHandler .html .htm AddType application/x-httpd-php .php .htm .html this file in htdocs or WWW folder and create your html page and write php code  in html file Example : myfolder    .htaccess    demo.html in demo.html <?php echo "My Name is rajeev "; ?>

unicode of rupees symbol

₹ Unicode of rupee symbol   &#x20b9; 

get all value of drop down list

One Two Three Fore Five <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script> function getalloption(){ arr=$('#ddlname option') for(i=0; i< arr.length; i++){ alert($(arr[i]).val()); alert($(arr[i]).text());  } } </script> <select name="ddlnane" id="ddlname" > <option value="1"> One </option> <option value="2"> Two </option> <option value="3"> Three </option> <option value="4"> Fore </option> <option value="5"> Five </option> </select> <input type="button" onclick="getalloption();" value="getOption"  />

url encryption and decryption in php

<?php $ide=5 ; $id= base64_encode($ide);  // convert to  NQ== echo base64_decode($id); ?> // output  5

remove leading zeros in javascript

Mobile No(beginning With Zero ) : <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script> function removeZero(s) {   while (s.substr(0,1) == '0' && s.length>1) { s = s.substr(1,500); }   return s; } function removeFirstZero(){ alert("orisinal value : "+$('#txtmobile').val()); var mob=removeZero($('#txtmobile').val()); alert("After remove Zero :  "+mob); $('#txtmobile').focus(); return false ; } </script>  Mobile No(beginning  With Zero ) :  <input type="text" name="txtmobile" id="txtmobile"   style="width:300px"  class="required"/> <input type="submit" name="btnsubmite" class="myButton" onclick="return removeFirstZero();" id="btnsubmite" value=" Get Value "/>

how to get all options of a select using javascript

PHP JAVASCRIPT CSS MYSQL <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script> function getalllist(){ var len = document.addform.ddllist.length;  // alert(len); var txt ='' ; // alert(len); var values=''; arr=$("#ddllist option"); for(var i = 0; i < len ; i++) { values+=document.addform.ddllist.options[i].value +"------" ; // form name  select box name txt+=document.addform.ddllist.options[i].text +"------" ; } alert("All Values : "+ values); alert("All Text Values : "+ txt); } </script> <form   name="addform" method="post" action="#" id="addform"> <select multiple="multiple" name="ddllist" id="ddllist" > <option value="php">PHP </option> <option value="js">JAVASCRIPT </option...

jquery check only one checkbox

  how to check only one checkbox in gridview <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script language="javascript"> function checkOnly(x)   {   $('.checkbox').attr("checked", false);     $(x).attr("checked", true);   }       </script> </head> <body> <form > <input type="checkbox" name="cb1" value="1" class="checkbox" onclick="checkOnly(this)"> <input type="checkbox" name="cb2" value="1" class="checkbox"  onclick="checkOnly(this)"> <input type="checkbox" name="cb3" value="1" class="checkbox"  onclick="checkOnly(this)"> </form>

how to prevent enter key submitting form

Name : Emai : <script>  $(document).keypress(function(e) {             if (e.which == 13) {             var $targ = $(e.target);             if (!$targ.is("textarea") && !$targ.is(":button,:submit")) {                 var focusNext = false;                 $(this).find(":input:visible:not([disabled],[readonly]), a").each(function() {                     if (this === e.target) {                         focusNext = true;                     }                     else if (focusNext) {                       ...

php string to javascript array

<?php  $str="RAJEEV~@~DHAR~@~DWIVEDI";   ?> <script> function getarray(x){ var str="<?php echo $str ; ?> "; var arr=str.split('~@~'); alert(arr[0]); alert(arr[1]); alert(arr[2]); } </script> <input type="button" value="getarray" name="GET ARRAY" onclick="getarray();"  />

How to php convert associative array to indexed array in PHP

get index  of array in php <?php $arr =array( 'index1'  => 'value1'  ,  "index2"  => 'value2'  ,  "index3" => 'value3' );  $ar = array_values ( $arr );  // convert to indexing  array  $key = array_keys ( $arr );  // get index name  for( $i = 0 ;  $i <  count ( $ar ) ;  $i ++){ echo  $key [ $i ]. "=" . $ar [ $i ]. "<br> " ; }   ?> output index1=value1 index2=value2 index3=value3

shortcut key for internet

1. how to clear all history bookmark from firefox  Press Ctrl+Shift+Del  

how to add value in array in php

How to Add more value in php array  <?php array_push (array  name  , value1,value2,value3,.... ); $ss =array();  // array declaration array_push ( $ss ,'val1' );   // array name , value ?>

how to add 30 days to a date in javascript

<script> function today(x){ y=parseInt(x); var d1=new Date((new Date()).getTime() + y*24*60*60*1000) ; var rr = d1.toString('yyyy-MM-dd'); a=rr.split(' '); d=a[2]+'-'+a[1]+'-'+a[3]; //return d ; alert(d); } </script> <input type="button" onclick="return today(0);" value="Today date"  /> <input type="button" onclick="return today(25);" value="NEXT 25 Days Date"  /> date picker in jquery   $( ".txtdate" ).datepicker({ changeMonth: true, changeYear: true }); $( ".txtdate" ).datepicker( "option", "dateFormat", "dd-M-yy");         $( ".txtdate" ).val(today('0')); 1. download necessary file from jquery  2. call txtdate class in input box

database connection in cakephp

database connection in cakephp 1. O pen app / config / database.php  <?php public $default  = array(          'datasource'  =>  'Database/Mysql' ,          'persistent'  =>  false ,          'host'  =>  'localhost' ,          'login'  =>  'user' ,          'password'  =>  '' ,  // here password          'database'  =>  'cakephp' ,  // its my database name          'prefix'  =>  '' ,          //'encoding' => 'utf8',      ); ?>

How To Use HTML Editor online

how to use html editor 1. download html editor from  http://nicedit.com/download.php 2.  copy and paste in a folder ,  Example: A   folder name 3. now create new folder within A  folder , Example : B     Folder name 4.   two file   nicEdit.js    and   nicEditorIcons.gif   (get from download)  paste on A folder 5. create demo.html file ,  on B  folder 6.   demo.html <script type="text/javascript" src="../nicEdit.js"></script> <script type="text/javascript"> // add text editor  bkLib.onDomLoaded(function(){ var myEditor = new nicEditor({fullPanel : true }).panelInstance('mytxtarea');   myEditor.addEvent('add', function() {   }); }); </script> <h4>Textarea</h4> <textarea name="area1" cols="40" id="mytxtarea" name="mytxtarea">     </textarea> 7.  how to get content from nicedit  function ge...

php warning mail function.mail failed to connect to mailserver at localhost port 25

php warning mail function.mail failed to connect to mailserver at localhost port 25 php warning mail function.mail failed to connect to mailserver at localhost port 25 ini_set('SMTP' , 'Server address') how to find server address : open run and type :   ping www.google.in -t   // www.google.in your site address example : ini_set('SMTP' , '74.125.236.191')

how to create cookies in javascript

how to set cookie in javascript how to get cookie value in javascript <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script> function setCookie(){ document.cookie='mycookie';  alert('cookies Successfully set'); } function getCookie(){  var cv = document.cookie.split( ';');  alert(cv[0]);  // get cookies value } </script>  <input type="button" value="setCookie" onclick=" setCookie ();"  name="setcookie" />  <input type="button" name="getcookie" value="getcookie" onclick=" getCookie ();"  />

select only image file validation in javascript

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script> function imageOnly(){ var file = $('#txtfile').val(); ext = file.substr(file.lastIndexOf('.')+1); alert(ext); if(ext=='jpg' || ext=='png' || ext=='gif' || ext=='bmp' || ext=='tif' ){}else { alert('Please select only Image'); $('#txtfile').focus(); return false ;} } </script> <input type="file" name="txtfie" id="txtfile"  />  <input type="button" value="Upload File" onclick="return imageOnly();"  />

wordpress theme development tutorial

wordpress theme development tutorial http://net.tutsplus.com/tutorials/wordpress/how-to-create-a-wordpress-theme-from-scratch/

wordpress plugin development tutorial

wordpress plugin development tutorial http://corpocrat.com/2009/12/27/tutorial-how-to-write-a-wordpress-plugin/

case when then in mysql

gender = column name table = table name SELECT * , CASE   gender when 'm' then 'male'               when 'f' then 'Female'   else gender END as ty FROM  Table SELECT * , CASE  when   id > 5   then 'male'               when   id < 5   then 'Female'   else gender  END as ty FROM  Table

how to auto close alert box javascript

how to auto close alert box javascript how to auto close alert box javascript I am also searching this code , if you found please comment code here thanks