Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Thursday, 11 February 2016



you can use this code in the following cases:

1) if you want to save data on submitting form then,
replace onchange=“getSummary2(‘order’)” with onclick=“getSummary2(‘order’)”

2) if you want to save on key up then,
replace onchange=“getSummary2(‘order’)” with onKeyUp=“getSummary2(‘order’)”

3) if you want to save data on change then use the code as it is


---------------------------------------------html code-------------------------------------------------


----------------------------------------------------------------------------------------------------------
------------------------------------------javascript.js--------------------------------------------------
function getSummary2(pass)
{
var	id = document.getElementById("sp_order"+pass).value;
	//alert(pass);
   $.ajax({
     type: "GET",
     url: 'sp_orders.php',
     data: "order=" + id + "&&section_id=" + pass, 
// appears as $_GET['id'] @ your backend side
     success: function(data) {
           // data is ur summary
        //  $('#order').html(data);
		     }

   });

}

-------------------------------------------------------------------------------------------------------------
-----------------------------------------sp_orders.php---------------------------------------------------
include('connect.php');
 $timestamp_complete = date("Y-m-d");
 $order = $_GET['order'];
 $section_id = $_GET['section_id'];
 mysql_query(" UPDATE  d_o_sp_orders  SET status='0' 
WHERE section_id='$section_id'");
		
mysql_query(" INSERT INTO  table (`order_id`, `orders`,
 `section_id`, `status`, `status_timestamp`) VALUES 
(NULL, ' $order', '$section_id', '1', '$timestamp_complete')");

------------------------------------------------------------------------------------------------------------
                                                   

Sunday, 7 February 2016





You can generate unlimited textboxes and unlimited their sub-texboxes by using the below code..

HTML CODE


<input type='text' name=''></input> <input id='btnAdd' type='button' class='btn btn-primary' value='+' onclick='AddTextBox(".$duty_id[$x].")' />
<button onClick=\"toggle_visibility('watch');\">?</button> <div id='TextBoxContainer".$duty_id[$x]."'>
<!--Textboxes will be added here -->
</div>


 JAVASCRIPT CODE


function GetDynamicTextBox(value,id){
var counter='1';
return '<td></td><td><input name = "DynamicTextBox" type="text" value = "' + value + '" id="country'+ id +'" onkeyup="suggest(this.value,'+ id +')" /></td>' +
'<td><input type="button" value="-" class="btn btn-primary hide-print" id="rem_btn" onclick = "RemoveTextBox(this,'+ id +')" /></td>'

counter=counter + 1;
}

function AddTextBox(id) {
var div = document.createElement('DIV');
div.innerHTML = GetDynamicTextBox("",id);
document.getElementById("TextBoxContainer"+id).appendChild(div);
}

function RemoveTextBox(div,id) {
//alert(id);
document.getElementById("TextBoxContainer"+id).removeChild(div.parentNode);
}
For any query write me in comments or email me

Saturday, 8 February 2014

Convert an address to its Long, Lat:

First 23 lines of code will convert your address to its latitude and longitude.

Convert Long, Lat to its according Address:

Lines from 24 to 43 of below code will convert your  latitude and longitude its address.

Calculate Distance /between two Long, Lat:

Lines from 87 to onward of below code will calculate the distance between two given addressess.

NOTE: In case of any error, feel free to ask in comments.

1:  <?php  
2:  $postcode1 = urlencode("bb9 5sh"); // post code to look up in this case status however can easily be retrieved from a database or a form post  
3:    $request_url1 = "http://maps.googleapis.com/maps/api/geocode/xml?address=".$postcode1."&sensor=true"; // the request URL you'll send to google to get back your XML feed  
4:    $xml1 = simplexml_load_file($request_url1) or die("url not loading");// XML request  
5:    $status1 = $xml1->status;// GET the request status as google's api can return several responses  
6:    if ($status1=="OK") {  
7:      //request returned completed time to get lat / lang for storage  
8:      $lat1 = $xml1->result->geometry->location->lat;  
9:      $long1 = $xml1->result->geometry->location->lng;  
10:      echo "$lat1,$long1"; //spit out results or you can store them in a DB if you wish  
11:    }  
12:    if ($status1=="ZERO_RESULTS") {  
13:      //indicates that the geocode was successful but returned no results. This may occur if the geocode was passed a non-existent address or a latlng in a remote location.  
14:    }  
15:    if ($status1=="OVER_QUERY_LIMIT") {  
16:      //indicates that you are over your quota of geocode requests against the google api  
17:    }  
18:    if ($status1=="REQUEST_DENIED") {  
19:      //indicates that your request was denied, generally because of lack of a sensor parameter.  
20:    }  
21:    if ($status1=="INVALID_REQUEST") {  
22:      //generally indicates that the query (address or latlng) is missing.  
23:    }  
24:       function getaddress1($lat1,$long1)  
25:  {  
26:  $url1 = 'http://maps.googleapis.com/maps/api/geocode/json?latlng='.trim($lat1).','.trim($long1).'&sensor=false';  
27:  $json1 = @file_get_contents($url1);  
28:  $data1=json_decode($json1);  
29:  $status1 = $data1->status;  
30:  if($status1=="OK")  
31:  return $data1->results[0]->formatted_address;  
32:  else  
33:  return false;  
34:  }  
35:  $address1= getaddress1($lat1,$long1);  
36:  if($address1)  
37:  {  
38:  echo $address1;  
39:  }  
40:  else  
41:  {  
42:  echo "Not found";  
43:  }  
44:  echo "<br/>";  
45:  $postcode = urlencode("ab13"); // post code to look up in this case status however can easily be retrieved from a database or a form post  
46:    $request_url = "http://maps.googleapis.com/maps/api/geocode/xml?address=".$postcode."&sensor=true"; // the request URL you'll send to google to get back your XML feed  
47:    $xml = simplexml_load_file($request_url) or die("url not loading");// XML request  
48:    $status = $xml->status;// GET the request status as google's api can return several responses  
49:    if ($status=="OK") {  
50:      //request returned completed time to get lat / lang for storage  
51:      $lat = $xml->result->geometry->location->lat;  
52:      $long = $xml->result->geometry->location->lng;  
53:      echo "$lat,$long"; //spit out results or you can store them in a DB if you wish  
54:    }  
55:    if ($status=="ZERO_RESULTS") {  
56:      //indicates that the geocode was successful but returned no results. This may occur if the geocode was passed a non-existent address or a latlng in a remote location.  
57:    }  
58:    if ($status=="OVER_QUERY_LIMIT") {  
59:      //indicates that you are over your quota of geocode requests against the google api  
60:    }  
61:    if ($status=="REQUEST_DENIED") {  
62:      //indicates that your request was denied, generally because of lack of a sensor parameter.  
63:    }  
64:    if ($status=="INVALID_REQUEST") {  
65:      //generally indicates that the query (address or latlng) is missing.  
66:    }  
67:       function getaddress($lat,$long)  
68:  {  
69:  $url = 'http://maps.googleapis.com/maps/api/geocode/json?latlng='.trim($lat).','.trim($long).'&sensor=false';  
70:  $json = @file_get_contents($url);  
71:  $data=json_decode($json);  
72:  $status = $data->status;  
73:  if($status=="OK")  
74:  return $data->results[0]->formatted_address;  
75:  else  
76:  return false;  
77:  }  
78:  $address= getaddress($lat,$long);  
79:  if($address)  
80:  {  
81:  echo $address;  
82:  }  
83:  else  
84:  {  
85:  echo "Not found";  
86:  }  
87:  /*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/  
88:  /*::                                     :*/  
89:  /*:: This routine calculates the distance between two points (given the   :*/  
90:  /*:: latitude/longitude of those points). It is being used to calculate   :*/  
91:  /*:: the distance between two locations using GeoDataSource(TM) Products  :*/  
92:  /*::                                                                             :*/  
93:  /*:: Definitions:                              :*/  
94:  /*::  South latitudes are negative, east longitudes are positive      :*/  
95:  /*::                                     :*/  
96:  /*:: Passed to function:                          :*/  
97:  /*::  lat1, lon1 = Latitude and Longitude of point 1 (in decimal degrees) :*/  
98:  /*::  lat2, lon2 = Latitude and Longitude of point 2 (in decimal degrees) :*/  
99:  /*::  unit = the unit you desire for results              :*/  
100:  /*::      where: 'M' is statute miles                  :*/  
101:  /*::         'K' is kilometers (default)             :*/  
102:  /*::         'N' is nautical miles                 :*/  
103:  /*::                                              :*/  
104:  /*::                                            :*/  
105:  /*::                                          :*/  
106:  /*:: For enquiries, please comment below    :*/  
107:  /*::                                     :*/  
108:  /*::         Ahmed Developer             :*/  
109:  /*::                                     :*/  
110:  /*::                                     :*/  
111:  /*::                                     :*/  
112:  /*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/  
113:  function distance($lat3, $lon3, $lat4, $lon4, $unit) {  
114:   $theta = $lon3 - $lon4;  
115:   $dist = sin(deg2rad($lat3)) * sin(deg2rad($lat4)) + cos(deg2rad($lat3)) * cos(deg2rad($lat4)) * cos(deg2rad($theta));  
116:   $dist = acos($dist);  
117:   $dist = rad2deg($dist);  
118:   $miles = $dist * 60 * 1.1515;  
119:   $unit = strtoupper($unit);  
120:   if ($unit == "K") {  
121:    return ($miles * 1.609344);  
122:   } else if ($unit == "N") {  
123:     return ($miles * 0.8684);  
124:    } else {  
125:      return $miles;  
126:     }  
127:  }  
128:  echo "<br/>";  
129:  $mm=distance("$lat1", "$long1", "$lat", "$long", "M");  
130:  echo number_format((float)$mm, 2, '.', ''). " Miles<br>";  
131:  //echo distance("$lat1", "$long1", "$lat", "$long", "K") . " Kilometers<br>";  
132:  //echo distance("$lat1", "$long1", "$lat", "$long", "N") . " Nautical Miles<br>";  
133:  ?>  

Friday, 15 November 2013

By Default MySQL Server didn’t use a password to access it. And a default user name ‘root’ is used to access MySQL Server.

Manually we can set a new user name and a password to access MySQL Server.

·        Open this URL : http://localhost/phpmyadmin/
·        Click on the Privileges tab.
·        Here you may ‘Add a New User’ or edit privileges of default user.
·        Edit Privileges: User 'root'@'localhost'
·        Set a new password for default user ‘root’
·        Refresh the URL : http://localhost/phpmyadmin/

·        Now you will face an error like this:


It shows that you can not view Localhost without a password.

SOLUTION:

  • Open this file :
    • C:\wamp\apps\phpmyadmin3.2.0.1\config.inc
  • Find this statement:
    • $cfg['Servers'][$i]['password'] = '';
  • And replace with this statement:
    • $cfg['Servers'][$i]['password'] = 'yourpassword';