Wednesday, 30 September 2015

get distance between two address through google api in php

<?php
function get_distance($address1,$address2)
{
$address1_encode = urlencode($address1);
$address2_encode = urlencode($address2);
$addresses_string = "?origins=".$address1_encode."&destinations=".$address2_encode."&key=AIzaSyBf6kfop46PNbRUAG-VwHVrGlyvNunpw9o";
    $url = "https://maps.googleapis.com/maps/api/distancematrix/json".$addresses_string;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    $response = curl_exec($ch);
    curl_close($ch);
   
  return $response;
    //$status = $response_a->status;
}
if(isset($_POST['get_dis'])){
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$results = get_distance($address1,$address2);
$response_a = json_decode($results);

echo "status :- ";
echo $result_status = $response_a->status;
echo "<br/>";
echo "distance :- ";
echo  $distance = $response_a->rows[0]->elements[0]->distance->value;
echo " M";
}
 ?>
 <form action="" method="post">
 <input type="text" name="address1">&nbsp;&nbsp;&nbsp;
 <input type="text" name="address2">&nbsp;&nbsp;&nbsp;
 <input type="submit" name="get_dis" value="Get Distance">

 </form>

Monday, 28 September 2015

javascript add class step by step in loop.

<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script>
$(function () {
  var $anchors = $('.anchor');

  (function _loop(idx) {
    $anchors.removeClass('highlight').eq(idx).addClass('highlight');
    setTimeout(function () {
      _loop((idx + 1) % $anchors.length);
    }, 2000);
  }(0));
});
</script>
<style>
.highlight{
color:#FF0000;
font-size:24px;
}
</style>
<a class="anchor">A</a>
<a class="anchor">B</a>
<a class="anchor">C</a>
<a class="anchor">D</a>
<a class="anchor">E</a>
<a class="anchor">F</a>
<a class="anchor">G</a>

Wednesday, 5 August 2015

how to import sql file in database in php

function  import_db($mysql_username,$mysql_password,$mysql_host,$mysql_database)
{
    // Name of the file
    $filename = $file_path.'/sql/database.sql';
   

    // Connect to MySQL server
    $db_conn = mysqli_connect($mysql_host, $mysql_username, $mysql_password,$mysql_database) or die('Error connecting to MySQL server: ' . mysql_error());
    // Select database
    //mysql_select_db($mysql_database) or die('Error selecting MySQL database: ' . mysql_error());

    // Temporary variable, used to store current query
    $templine = '';
    // Read in entire file
    $lines = file($filename);
    // Loop through each line
    foreach ($lines as $line)
    {
    // Skip it if it's a comment
    if (substr($line, 0, 2) == '--' || $line == '')
        continue;

    // Add this line to the current segment
    $templine .= $line;
    // If it has a semicolon at the end, it's the end of the query
    if (substr(trim($line), -1, 1) == ';')
    {
        // Perform the query
        mysqli_query($db_conn,$templine) or print('Error performing query \'<strong>' . $templine . '\': ' . mysql_error() . '<br /><br />');
        // Reset temp variable to empty
        $templine = '';
    }
    }
    //echo "Tables imported successfully";

}

Thursday, 18 June 2015

html value set in php variable

<?php
$my_var = <<<EOD
<div onclick="pa('1','sdsa','12');">SOME HTML</div>
EOD;

echo $my_var;
?>

Saturday, 13 June 2015

redirect www to non www htaccess

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

Friday, 12 June 2015

date difference in php

$d1 = new DateTime("2009-07-01");
$d2 = new DateTime("2010-05-31");
var_dump($d1->diff($d2)->m + ($d1->diff($d2)->y*12));

Tuesday, 9 June 2015

jquery get month and year value on change in datepicker

<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery UI Datepicker - Display inline</title>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
  <script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script>
  $(function() {
  $( "#datepicker" ).datepicker({
  onChangeMonthYear :function(da,mon,ob){alert("Year-"+ da +" Month- " + mon);}
});
});
  </script>
</head>
<style>
.ui-datepicker table{display:none;}
</style>
<body>

Date: <div id="datepicker"></div>


</body>
</html>