Friday, November 30, 2012

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

Thursday, November 29, 2012

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###

Wednesday, November 28, 2012

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";
 }

Tuesday, November 6, 2012

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


Monday, November 5, 2012

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] => 14 )


Saturday, November 3, 2012

Regular Expression

Regular Expression in JavaScript




Regular Expression in php





Regular Expression in MySql