Monday, January 30, 2017

TIME AGO in PHP

<?php

//DATE FORMAT
//echo date("F d Y H:i:s");


// TESTING
function test($ts){

    echo time_passed($ts) . '<br />';



test(time());
test(strtotime("January 30 2017 07:41:08"));
test(time()-(60*17));
test(time()-((60*60*2) + (60*55)));
test(time()-(60*60*3+60));
test(strtotime('-1 day'));
test(strtotime('-13 days'));
test(strtotime('January 30 2017 07:31:08'));
test(strtotime('July 23 2016'));
test(strtotime('November 18 1999'));
test(strtotime('March 1 1937'));

//TESTING- end

//FUNCTION 
function time_passed($timestamp){
    //type cast, current time, difference in timestamps
    $timestamp      = (int) $timestamp;
    $current_time   = time();
    $diff           = $current_time - $timestamp;
   
    //intervals in seconds
    $intervals      = array (
        'year' => 31556926, 'month' => 2629744, 'week' => 604800, 'day' => 86400, 'hour' => 3600, 'minute'=> 60
    );
   
    //now we just find the difference
    if ($diff == 0)
    {
        return 'just now';
    }  

    if ($diff < 60)
    {
        return $diff == 1 ? $diff . ' second ago' : $diff . ' seconds ago';
    }      

    if ($diff >= 60 && $diff < $intervals['hour'])
    {
        $diff = floor($diff/$intervals['minute']);
        return $diff == 1 ? $diff . ' minute ago' : $diff . ' minutes ago';
    }      

    if ($diff >= $intervals['hour'] && $diff < $intervals['day'])
    {
        $diff = floor($diff/$intervals['hour']);
        return $diff == 1 ? $diff . ' hour ago' : $diff . ' hours ago';
    }  

    if ($diff >= $intervals['day'] && $diff < $intervals['week'])
    {
        $diff = floor($diff/$intervals['day']);
        return $diff == 1 ? $diff . ' day ago' : $diff . ' days ago';
    }  

    if ($diff >= $intervals['week'] && $diff < $intervals['month'])
    {
        $diff = floor($diff/$intervals['week']);
        return $diff == 1 ? $diff . ' week ago' : $diff . ' weeks ago';
    }

    if ($diff >= $intervals['month'] && $diff < $intervals['year'])
    {
        $diff = floor($diff/$intervals['month']);
        return $diff == 1 ? $diff . ' month ago' : $diff . ' months ago';
    }  

    if ($diff >= $intervals['year'])
    {
        $diff = floor($diff/$intervals['year']);
        return $diff == 1 ? $diff . ' year ago' : $diff . ' years ago';
    }
}

?>

Sunday, January 29, 2017

GET CURRENT DATE TIME IN PHP

function date_time_generated(){
     return 'Date and Time Generated : ' . date("m/d/Y H:i:s",time()+8*60*60 );  
   }

Time ago in PHP

function get_timeago( $ptime )
{
    $estimate_time = time() - $ptime;

    if( $estimate_time < 1 )
    {
        return 'less than 1 second ago';
    }

    $condition = array(
                12 * 30 * 24 * 60 * 60  =>  'year',
                30 * 24 * 60 * 60       =>  'month',
                24 * 60 * 60            =>  'day',
                60 * 60                 =>  'hour',
                60                      =>  'minute',
                1                       =>  'second'
    );

    foreach( $condition as $secs => $str )
    {
        $d = $estimate_time / $secs;

        if( $d >= 1 )
        {
            $r = round( $d );
            return 'about ' . $r . ' ' . $str . ( $r > 1 ? 's' : '' ) . ' ago';
        }
    }
}

$timeago=get_timeago(strtotime('2017/01/30 1:57'));
echo $timeago;


 format ‘YYYY-MM-DD H:M:S’

Friday, January 27, 2017

DELETE ROW WITHOUT REFRESHING PAGE IN PHP



<tr><a href="" id="'.$row['rec_id'].'" class="delbutton"><b>Delete</b></a></tr>

<script type="text/javascript" >
        $(function() {
            $(".delbutton").click(function() {
                var del_id = $(this).attr("id");
                var info = 'id=' + del_id;
var thisTableRow = $(this).closest('tr');
                if (confirm("Sure you want to delete this post? This cannot be undone later.")) {
                    $.ajax({
                        type : "POST",
                        url : "delete_pdf.php", //URL to the delete php script
                        data : info,
                        success : function() {
alert("PDF Successfully deleted!");
 $(thisTableRow).hide("fast");
                        }
                    });
                }
                return false;
            });
        });
 </script>


delete_pdf.php

<?php
 require_once('mysql_connect.php');
$id=$_POST['id'];
$delete = "DELETE FROM uploaded_tax_files WHERE rec_id='$id'";
$result = mysql_query($delete) or die(mysql_error());

?>

Monday, January 23, 2017

How to Connect FileZilla To Hostinger






USE PHP INSIDE CSS

filename : style.php
<?php 
header("Content-type: text/css");  
$color1 = "#000";
$color2 = "#fff";
?>
body {
    background-color: <?php echo $color1; ?>;
}
h1 {
    color: <?php echo $color2; ?>;
}
Include your dynamic css something like this:
filename : index.php

<link href="styles.php" media="screen" rel="stylesheet" type="text/css" />

Friday, January 20, 2017

AUTO ADJUST IFRAME ACCORDING TO THE SIZE OF CONTENT

1 .   Paste inside <head>

<script>
 function autoSizeIframe(obj) {
obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
obj.style.width = obj.contentWindow.document.body.scrollWidth + 'px';
 }
</script>

2.add this to your code

<iframe src="your_link.php" frameborder="0" scrolling="no" onload="autoSizeIframe(this)" />

Wednesday, January 18, 2017

Create Database

<?php
$servername = "localhost";
$username = "root";//username
$password = "root";//password

// Create connection
$conn = mysqli_connect($servername, $username, $password);
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

// Create database
$sql = "CREATE DATABASE databasename";
if (mysqli_query($conn, $sql)) {
    echo "Database created successfully";
} else {
    echo "Error creating database: " . mysqli_error($conn);
}

mysqli_close($conn);
?>

PHP Definition


What is PHP?


PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.


PHP: (Hypertext Preprocessor) is a  scripting language that is especially u for web development and can be embedded into HTML.