Tuesday, October 8, 2019

Month and Year MySQL format


$sql = $sql." AND MONTH(byr_tarikh)='".$bulan."' ";
$sql = $sql." AND YEAR(byr_tarikh)='".$tahun."' ";

and for loop

<?php
for ($x = 0; $x <= 10; $x++) {
    echo "The number is: $x <br>";
}
?>



Saturday, October 5, 2019

Create Sentence Break in PHP

Create below function in PHP page
 
function myTruncate2($string, $limit, $break=" ", $pad="")
{
     // return with no change if string is shorter than $limit
     if(strlen($string) <= $limit) return $string;

     $string = substr($string, 0, $limit);
     if(false !== ($breakpoint = strrpos($string, $break))) {
                $string = substr($string, 0, $breakpoint);
      }
     return $string . $pad; 
 }

Call to function as below :

$str_add1 = $this->myTruncate2($data->ahli_coalamat, 48);
 


SQL date format in MYSQL PHP

SELECT date_format(byr_tarikh,'%d/%m/%y') AS formatDate from TBL_NAME

Result
----------------------

20/03/1974
01/03/1999