Friday, October 10, 2014

MySQL Sintax To Find Unmatched Records Between Two Table Find difference record between two tables. Here the code: SELECT username FROM ( SELECT username FROM member_option UNION ALL SELECT username FROM member WHERE status='1' ) tbl GROUP BY username HAVING count(*) = 1 ORDER BY username; Good Luck ...
MySQL Sintax to Find Duplicate Entries Here the code: SELECT column FROM table_name group by column having count(*) >= 2 Good Luck ...

Thursday, August 21, 2014

Adding foreign key in MySQL This sql sintax can create link betwen key in some tables. Please used in InnoDB only. Here the code: ALTER TABLE child_table_name ADD FOREIGN KEY (P_ID) REFERENCES parent_table_name (P_ID) #example: ALTER TABLE member_detail ADD FOREIGN KEY (username) REFERENCES member (username) #foreign key will be deleted/updated if primary key deleted/updated ON DELETE CASCADE ON UPDATE CASCADE #parent will not be deleted if any child row exist ON DELETE RESTRICT #The script will be: ALTER TABLE member_detail ADD...

Wednesday, March 26, 2014

Command Linux To Chmod File Only Or Directory Only Recursively In All Subdirectory This command can chmod file only or directory only recursively. Here the code: sudo su #this command to chmod file only recursively find . -type f -exec chmod 644 {} \; #this command to chmod directory only recursively find . -type d -exec chmod 755 {} \; Good Luck ...

Monday, March 24, 2014

PHP Code To Convert DateTime To Your Prefer Timezone This function can convert DateTime to your prefer timezone. Here the code: function convertTimezone($date,$zone){ $dates   = explode(" ", $date); $tgl     = explode("-",$dates[0]); $time    = explode(":",$dates[1]); $newtime = mktime($time[0]+$zone,$time[1],$time[2],$tgl[1],$tgl[2],$tgl[0]); // H,i,s,m,d,Y $newdate = date('Y-m-d H:i:s',$newtime); return $newdate; } $date = "2014-03-30 06:01:09"; $newDate = convertTimezone($date,"+7"); echo $newDate; Good...
PHP Code To Make A Random Password This function can generate a random password, use alphanumeric character, and eliminating the ambiguous character. Here the code: function randomPassword(){ $digit = 8; $karakter = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"; srand((double)microtime()*1000000); $i = 0; $pass = ""; while ($i <= $digit-1) { $num = rand() % 32; $tmp = substr($karakter,$num,1); $pass = $pass.$tmp; $i++; } return $pass; } $password = randomPassword() echo $password; Good Luck ...
PHP Code To Limiting Words Number In PHP This function can limiting words number. Usually this used to limit name of person. Here the code: function word($word,$limit){ $result=''; $words=@explode(" ",$word); for($i=0;$i<=$limit-1;$i++){ $result.=@$words[$i]." "; } return $result; } $name = "iben arief bin padi"; echo word($name,1); // output: iben echo word($name,2); // output: iben arief echo word($name,3); // output: iben arief bin echo word($name,4); // output: iben arief bin padi Good Luck ...
PHP Code To Auto Detect URL in Text Then Make Clickable This function can auto detect URL in  all text, then make the URL clickable. Here the code: function autolink( &$text, $target='_blank', $nofollow=true ) {   // grab anything that looks like a URL...   $urls  =  _autolink_find_URLS( $text );   if( !empty($urls) ) // i.e. there were some URLS found in the text   {     array_walk( $urls, '_autolink_create_html_tags', array('target'=>$target, 'nofollow'=>$nofollow) );     $text...
PHP Code To Send Email With Swiftmailer Library Before use this function, please download swiftmailer library from this source http://swiftmailer.org/download. This function can send email using PHP with Swiftmailer Library. Place This file in same path with folder 'lib/'. This function is automatic detect body of message in plain text or html. Here the code: function sendEmail($method,$subject,$from,$to,$body){ require_once dirname(__FILE__).'/lib/swift_required.php'; if($method=="smtp"){ $smtp     = "smtpaddress"; // ex: smtp.mandrillapp.com $port...
PHP Code To Calculate The Difference Between Two Dates This function can calculate the difference between two dates. Here the code: function diff($firstDate,$secondDate){    $first=explode("-",$firstDate);    $second=explode("-",$secondDate);    $first = @GregorianToJD($first[1], $first[2], $first[0]);    $second = @GregorianToJD($second[1], $second[2], $second[0]);    $diff = $second - $first; return $diff; } echo diff("2014-02-25","2014-02-28"); // output is 3 Good Luck ...
PHP Code To Resize and Crop Image This function resize image and crop image. Here the Code: // Function to resize image function resizeImage($image,$width,$height,$scale) { $newImageWidth = ceil($width * $scale); $newImageHeight = ceil($height * $scale); $newImage = imagecreatetruecolor($newImageWidth,$newImageHeight); $source = imagecreatefromjpeg($image); imagecopyresampled($newImage,$source,0,0,0,0,$newImageWidth,$newImageHeight,$width,$height); imagejpeg($newImage,$image,90); chmod($image, 0777); return $image; } // Function to...

Sunday, March 23, 2014

PHP Code To Validate Email Address and Domain This function can Validate Email Address and Domain. Here the Code: $email = "test test@yahoo.com"; // Invalid Formating //$email = "testtest@yahoo.comx"; // Invalid Domain //$email = "testtest@yahoo.com"; // Valid Email // validate address formating if (filter_var($email, FILTER_VALIDATE_EMAIL) != FALSE) {     echo "Valid email address formatting!\n"; }else{     echo "Invalid formatting\n"; } // validate domain of email $domain = substr($email, strpos($email, '@') + 1); if...
PHP code to make Indonesia Rupiah Format Simple Indonesia Rupiah Format in PHP. Here The Code: function rupiah($a){ if(stripos($a, ".")===FALSE){$a = $a.".00";} $pecah    = explode(".", $a); $depan    = strrev($pecah[0]); $belakang = $pecah[1]; $jum      = strlen($depan); $res      = ""; for($i=0;$i<=$jum-1;$i++){ if($i%3==0 and $i!=0){$res.=".".$depan[$i];} else{$res.=$depan[$i];} } return "Rp ".strrev($res).",".$belakang; } $a = "2090705.57"; echo rupiah($a); Good Luck...
PHP Code To Find All Directory Or File Recursively This function can find all directory or file in a path. Here the Code: function glob_recursive($pattern, $flags = 0){ $files = glob($pattern, $flags); foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir){ $files = array_merge($files, glob_recursive($dir.'/'.basename($pattern), $flags)); } return $files; } $results = glob_recursive("*", $flags = 0); foreach ($results as $result) { $type = is_file($result) ? "File" : "Dir"; echo $result."\n".$type."\n\n"; } Good Luck...