Total Pageviews

Tuesday, September 13, 2011

Find distance between two Geographical positions

Haversine formula:

a = sin²(Δlat/2) + cos(lat1).cos(lat2).sin²(Δlong/2)
c = 2.atan2(√a, √(1−a))
d = R.c
where R is earth’s radius (mean radius = 6,371km);
note that angles need to be in radians to pass to trig functions!
JavaScript:
var R = 6371; // km
var dLat = (lat2-lat1).toRad();
var dLon = (lon2-lon1).toRad();
var lat1 = lat1.toRad();
var lat2 = lat2.toRad();

var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c;

Monday, September 12, 2011

To Save the Jquery sortable data in database

<ul id="sortable" >
<li id="id1">elem 1 </li >
<li id="id2">elem 2 </li >
<li id="id3">elem 3 </li >
<li id="id4">elem 4 </li >
</ul >

$(document).ready(function(){
$('#sortable').sortable({
update: function(event, ui) {
var sortData= $(this).sortable('toArray').toString();
$.get('ajaxfilename.php', {order:sortData});
}
});
});

here sortData will get changed whenever a change is made in the Sortable

Tuesday, July 19, 2011

Mysql tricky stuff

1) Delete duplicate entry/data from mysql database.

delete from table1
USING table1, table1 as aliastable
WHERE (NOT table1.ID=aliastable.ID)
AND (table1.field_name=aliastable.field_name).
above query is a nice example of self-join.

2) Import large database files
run below command on command prompt.
mysql -p -u username database_name < file.sql

3) if you get following error
#1467 - Failed to read auto-increment value from storage engine
this happens because of 2 reasons your auto increment field length is too small
or it is a bug in mysql.
follow these steps
1)show table status;
if it shows a very large value for your auto increment column
use the query
ALTER TABLE table_name AUTO_INCREMENT =2009;

Wednesday, July 13, 2011

How to get last insert id in MYSQL

There are 3 ways of getting last insert in mysql

1) mysql_insert_id();
2) LAST_INSERT_ID();
3) my fetching max(id) from column, this is generally not a good method for high traffic websites

Friday, June 24, 2011

Some Useful Php Tips

1) to get the file extension during file upload use:
$ext = strrchr($_FILES['file']['name'], '.');

2) To upload a large file, use following tips
pass 'MAX_FILE_SIZE' constant as a parameter and set its size.
this can be done by either defining it as a constant
define(MAX_FILE_SIZE,'1234561')
or passing it in hidden field like this





3) to get all the folders,without files

$dirs = array_filter(glob($path.'*'), 'is_dir');

Thursday, June 9, 2011

Calling dynamic data in every header file

Will answer it soon

IE session issue in Codeigniter

You can try following things:

1) If session is working fine in your system but having problem on the server,
then set the time of server. the problem occurs due to difference in time.

2) try to set the path like
$config['cookie_domain'] = "meerutwala.com";
$config['cookie_path'] = "/app";

because IE need domain name for cookie.

3) Try this also
change
$config['sess_cookie_name'] = 'ci_session';
to
$config['sess_cookie_name'] = 'cisession';
because IE don't like underscore in its name
4) if nothing is working for you then go for native session :(