Monday 28 December 2015

Get near by Location using latitude and longitude from php and mysql in google map Kilometer

Get near by Location using latitude and longitude from php and mysql in google map Kilometer

To search by miles  instead of kilometers, replace 6371 with .3959

<?php


$username="root";
$password="";
$database="googlemap";



// Get parameters from URL
$center_lat = 23.036730;
$center_lng = 72.516373;
$radius = 6;


$connection=mysql_connect ("localhost", $username, $password);
if (!$connection) {
  die("Not connected : " . mysql_error());
}

// Set the active mySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
  die ("Can\'t use db : " . mysql_error());
}

// Search the rows in the mstuser table
$query = sprintf("SELECT usermail, res_name, lat, lng, ( 6371  * acos( cos( radians('%s') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( lat ) ) ) ) AS distance FROM mstuser HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20",


  mysql_real_escape_string($center_lat),
  mysql_real_escape_string($center_lng),
  mysql_real_escape_string($center_lat),
  mysql_real_escape_string($radius));

  /*$query = sprintf("SELECT address, name, lat, lng, ( 3959 * acos( cos( radians('%s') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < 25 ORDER BY distance LIMIT 0 , 20",


  mysql_real_escape_string($center_lat),
  mysql_real_escape_string($center_lng),
  mysql_real_escape_string($center_lat),
  mysql_real_escape_string($radius));*/
$result = mysql_query($query);

$result = mysql_query($query);
if (!$result) {
  die("Invalid query: " . mysql_error());
}

header("Content-type: application/json");
$i=0;
// Iterate through the rows, adding XML nodes for each
while ($row = @mysql_fetch_assoc($result)){


  $data[$i]['usermail'] = $row['usermail'];
  $data[$i]['res_name'] = $row['res_name'];
  $data[$i]['lng'] = $row['lng'];
  $data[$i]['lat'] = $row['lat'];
  $data[$i]['distance'] = $row['distance'];

  $i++;

}

echo json_encode($data);
?>

Sunday 27 December 2015

How Retrieve Latitude and Longitude via Google Maps API Using it's Address?

Hello

Retrieve Latitude and Longitude via Google Maps API Using it's Address

Here Sample code for Retrieve Latitude and Longitude via Google Maps API Using it's Address

check It can be Use full.


<!DOCTYPE html>
<html>
    <head>
        <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=places"></script>
        <script type="text/javascript">
        function initialize() {
        var address = (document.getElementById('my-address'));
        var autocomplete = new google.maps.places.Autocomplete(address);
        autocomplete.setTypes(['geocode']);
        google.maps.event.addListener(autocomplete, 'place_changed', function() {
            var place = autocomplete.getPlace();
            if (!place.geometry) {
                return;
            }

        var address = '';
        if (place.address_components) {
            address = [
                (place.address_components[0] && place.address_components[0].short_name || ''),
                (place.address_components[1] && place.address_components[1].short_name || ''),
                (place.address_components[2] && place.address_components[2].short_name || '')
                ].join(' ');
        }
      });
}
function address_lat_lag() {
    geocoder = new google.maps.Geocoder();
    var address = document.getElementById("my-address").value;
    geocoder.geocode( { 'address': address}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {

      alert("Latitude: "+results[0].geometry.location.lat());
      alert("Longitude: "+results[0].geometry.location.lng());
 
  document.getElementById("lat").value = results[0].geometry.location.lat();
   document.getElementById("lag").value = results[0].geometry.location.lng();
      }

      else {
        alert("Geocode was not successful for the following reason: " + status);
      }
    });
  }
google.maps.event.addDomListener(window, 'load', initialize);

        </script>
    </head>
    <body>
        <input type="text" id="my-address">
        <button id="getCords" onClick="address_lat_lag();">getLat&Long</button>
       
        You can save here as textbox value
        <br/>
        <label>Latitude</label>
        <input type="text" id="lat"  name="lat"/>
         <label>Longitude</label>
        <input type="text" id="lag"  name="lag"/>
    </body>
</html>

Friday 18 December 2015

validation method added in jquery like selectbox validation,date formate(dd-mm-yyyy),price(decimal value),phone number,highlight error.

highlight error in jquery validation

validation method added in jquery like selectbox validation,date formate(dd-mm-yyyy),price(decimal value),phone number,highlight error.


selectbox value set option value 0 then set valueNotEquals:"0"
date formate set dateFormat: true and it validation of dd-mm-yyyy formate
price we can to set as decimal  float_number: true
phone if we want to set +91-10degits then set   indiaPhone: true

if you want no highlight you error then it can be added this method


        highlight: function(element) {
            $(element).css({
                "background-color": "rgba(60, 141, 188, 0.52)",
                "border-color": "red"
            });
        },
        unhighlight: function(element) {
            $(element).css({
                "background-color": "",
                "border-color": ""
            });
           
            here added on error color and border you can chanage here to highlight your textbox or any else input

 $('#test').validate({

        rules: {
            coupon_code: {
                required: true
            },
            price: {
                required: true,
                maxlength: 10,
                float_number: true
            },
            vendorname: {
                valueNotEquals: "0"
            },          
            startdate: {
                dateFormat: true
            },
             phone1: {
                indiaPhone: true,
                maxlength: 13
            },
            enddate: {
                dateFormat: true
            },
        },


        highlight: function(element) {
            $(element).css({
                "background-color": "rgba(60, 141, 188, 0.52)",
                "border-color": "red"
            });
        },
        unhighlight: function(element) {
            $(element).css({
                "background-color": "",
                "border-color": ""
            });
        }

    });




});


/** validation for Selectbox */


$.validator.addMethod("valueNotEquals", function(value, element, arg) {
    return arg != value;
}, "Please Select Value");



/** validation for Phone Number  in textbox */

$.validator.addMethod("indiaPhone", function(value, element, arg) {

    var filter = /^[0-9-+]+$/;
    var phone = filter.test(value)


    return arg = phone;


}, "Plese Enter Number");

/** validation for decimal value in textbox */

$.validator.addMethod("float_number", function(value, element, arg) {

    var filter = /^\d{0,8}(\.\d{1,2})?$/;
    var float_number = filter.test(value)


    return arg = float_number;


}, "please Enter Valid Number");


/** date validation for dd-mm-yyyy */

$.validator.addMethod("dateFormat",
    function(value, element, arg) {
        var dateformat = /^(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}$/;

        var validate = dateformat.test(value);


        return arg = validate;

    },
    "Please Enter a date in the format dd-mm-yyyy.");

Monday 7 December 2015

Checked Checkbox Value Using Class In Jquey


Here Full Example

How TO Get All Checkbox value Using It's class

Checked Checkbox Value Using Class In Jquey


We can use on change event for every checkbox and getting value of it class.
use push to collect value check it.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Checkbox Value Example</title>
</head>
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script type="application/javascript">
function getValueUsingClass(){
   /* declare an checkbox array */
   var chkArray = [];
  
   /* look for all checkboes that have a class 'chk' attached to it and check if it was checked */
   $(".chk:checked").each(function() {
   chkArray.push($(this).val());
   });
  
   /* we join the array separated by the comma */
   var selected;
   selected = chkArray.join(',') + ",";
  
   /* check if there is selected checkboxes, by default the length is 1 as it contains one single comma */
   if(selected.length > 1){
   alert("You have selected " + selected);
  
  
   }else{
   alert("Please at least one of the checkbox");
   }
   }
</script>
<body>
<input type="checkbox" class="chk" name="test" value="checked1" onchange="getValueUsingClass()"  />checked1
<input type="checkbox" class="chk" name="test" value="checked2"  onchange="getValueUsingClass()"  />checked2
<input type="checkbox" class="chk" name="test" value="checked3" onchange="getValueUsingClass()"  />checked3
<input type="checkbox" class="chk" name="test" value="checked4" onchange="getValueUsingClass()"  />checked4
<input type="checkbox" class="chk" name="test" value="checked5" onchange="getValueUsingClass()"  />checked5
<input type="checkbox" class="chk" name="test" value="checked6" onchange="getValueUsingClass()"  />checked6
<input type="checkbox" class="chk" name="test" value="checked7" onchange="getValueUsingClass()"  />checked7
</body>
</html>

Sunday 6 December 2015

How to Compare two strings using stored procedure in Mysql


 Compare two strings using stored procedure in Mysql
  1. Only need one (1) equals sign to evaluate
 DECLARE @tempo VARCHAR(20)
    SET @tempo = 'test'

IF @tempo = 'test'
  SELECT 'yes'
ELSE
  SELECT 'no'

return yes of this output

DECLARE @tempo VARCHAR(20)
    SET @tempo = 'test1'

IF @tempo = 'test'
  SELECT 'yes'
ELSE
  SELECT 'no'

return no in this output


you can also use interger  as value

set below type code for integer


 SET @temp = 1

IF @temp = 1
  SELECT 'yes'
ELSE
  SELECT 'no'
 
  return yes
 
 


IF @temp = 2
  SELECT 'yes'
ELSE
  SELECT 'no'
 
  return no


Split String with comma Loop in Mysql store Proceture Example

Hello

Here Very Usefull for Split String with comma Loop in Mysql store Proceture Example

Split String with comma Loop in Mysql store proceture
this fully example how to use

Loop In Mysql

and split string in mysql

begin
  
   
   
    SET @InitCounter := 1;
      SET @Param := "11,22,33,44,";
    
 
  
  
      
    myLoop: loop 
   
 SET @NextCounter := LOCATE(',',@Param);

 SET @SUBSTR := SUBSTRING(@Param,@InitCounter,@NextCounter);

 SET @Param := REPLACE(@Param,@SUBSTR,'');

 SET @SUBSTR:= REPLACE(@SUBSTR,',','');

 SET @ParamLength := LENGTH (@Param);


 SELECT @SUBSTR;




                      
        if  
       
             @ParamLength = 0
        then
            leave myLoop;             
        end if;
       
    end loop myLoop;                   
   
END

Thursday 3 December 2015

Making radio buttons look like buttons and getting radio and label value



Hello

Making radio buttons look like buttons and getting radio and label value

if getting label value then please replace this css

.donate-now input[type="radio"] {
    opacity:0.01;
    z-index:100;
    height:100%;
    width:100%;
}

to

.donate-now input[type="radio"] {
    opacity:0.01;
    z-index:100;
   }
<script>

$(document).ready(function(e) {


// Get Value Using Label
$('.hour').click(function(){
//alert('hi');

var lable_value = $(this).attr('month');

alert(lable_value);

});

//Get Value using Radio Button

$('input[name="hours"]:radio').click(function(){


radio_value = $(this).val();

alert(radio_value);
});
       
    });
</script>


<ul class="donate-now">
<li>
    <input type="radio" name="hours" value="1" >
    <label class='hour' for="hour" month='hour'>hour</label>
</li>
<li>
    <input type="radio" name="hours" value="4" >
    <label class='hour' for="4hour"  month='4hour'>4hour</label>
</li>
<li>
    <input type="radio" name="hours" value="8" >
    <label class='hour' for="8hour"  month='8hour'>8hour</label>
</li>
<li>
    <input type="radio" name="hours" value="24" >
    <label class='hour' for="24hour"  month='3days'>24hour</label>
</li>

<li>
    <input type="radio" name="hours" value="3" >
    <label class='hour' for="3days"  month='3days'>3days</label>
</li>

<li>
    <input type="radio" name="hours" value="all" >
    <label class='hour' for="all"  month='all'>all</label>
</li>

</ul>

<style>
.donate-now {
     list-style-type:none;
     margin:25px 0 0 0;
     padding:0;
}

.donate-now li {
     float:left;
     margin:0 5px 0 0;
    width:100px;
    height:40px;
    position:relative;
}

.donate-now label, .donate-now input {
    display:block;
    position:absolute;
    top:0;
    left:0;
    right:0;
    bottom:0;
}

.donate-now input[type="radio"] {
    opacity:0.01;
    z-index:100;
height:100%;
width:100%;
}

.donate-now input[type="radio"]:checked + label,
.Checked + label {
    background:yellow;
}

.donate-now label {
     padding:5px;
     border:1px solid #CCC;
     cursor:pointer;
    z-index:90;
}

.donate-now label:hover {
     background:#DDD;
}
</style>

Wednesday 2 December 2015

Search by key and value in a multidimensional array in PHP

Hello

Example of Search by key and value in a multidimensional array in PHP


I have to get Code How to search array it key value of array example here

function array_search_by_key($array, $key, $value)
{
    $results = array();

    if (is_array($array)) {
        if (isset($array[$key]) && $array[$key] == $value) {
            $results[] = $array;
        }

        foreach ($array as $subarray) {
            $results = array_merge($results, array_search_by_key($subarray, $key, $value));
        }
    }

    return $results;
}

$user = array(0 => array(id=>1,name=>"test1",address=>"add1",gendor=>"male"),
             1 => array(id=>2,name=>"test2",address=>"add2",gendor=>"female"),
             2 => array(id=>3,name=>"test3",address=>"add3",gendor=>"male"));

print_r(array_search_by_key($user, 'name', 'test2'));
print_r(array_search_by_key($user, 'id', '1'));
print_r(array_search_by_key($user, 'address', 'add3'));
print_r(array_search_by_key($user, 'gendor', 'male'));