Click here to Skip to main content
15,897,187 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: When is a double a string Pin
Luc Pattyn13-May-10 5:33
sitebuilderLuc Pattyn13-May-10 5:33 
GeneralRe: When is a double a string Pin
Electron Shepherd13-May-10 6:59
Electron Shepherd13-May-10 6:59 
GeneralRe: When is a double a string Pin
Luc Pattyn13-May-10 7:35
sitebuilderLuc Pattyn13-May-10 7:35 
GeneralRe: When is a double a string Pin
Electron Shepherd13-May-10 7:41
Electron Shepherd13-May-10 7:41 
GeneralRe: When is a double a string Pin
supercat914-May-10 6:36
supercat914-May-10 6:36 
GeneralRe: When is a double a string Pin
PIEBALDconsult13-May-10 4:39
mvePIEBALDconsult13-May-10 4:39 
GeneralRe: When is a double a string Pin
Chris Maunder13-May-10 15:50
cofounderChris Maunder13-May-10 15:50 
GeneralSelecting all coordinates withing a distance Pin
Jeroen De Dauw12-May-10 12:51
Jeroen De Dauw12-May-10 12:51 
This little gem is used to construct the where condition for an SQL query that selects all coordinates within a certain distance from a point (in a PHP app). The coordinates are stored in the db in a single field, where the lat and lon are separated by a comma. The SQL is splitting on that and running a whole bunch of calculations. The table can be millions of entries big. I kid you not.

$distance = "ROUND(((ACOS( SIN({$latitude} * PI()/180 ) * SIN(SUBSTRING_INDEX({$tablename}.{$fieldname}, ',',1) * PI()/180 ) + COS({$latitude} * PI()/180 ) * COS(SUBSTRING_INDEX({$tablename}.{$fieldname}, ',',1) * PI()/180 ) * COS(({$longitude} - SUBSTRING_INDEX({$tablename}.{$fieldname}, ',',-1)) * PI()/180))*180/PI())*60*1.1515),6)";

$where = "{$distance} <= " . $dbs->addQuotes( "5" );
Jeroen De Dauw

Forums ; Blog ; Wiki

QuestionRe: Selecting all coordinates withing a distance Pin
Chris Meech13-May-10 3:09
Chris Meech13-May-10 3:09 
AnswerRe: Selecting all coordinates withing a distance Pin
Jeroen De Dauw13-May-10 3:12
Jeroen De Dauw13-May-10 3:12 
AnswerRe: Selecting all coordinates withing a distance Pin
elchupathingy13-May-10 3:54
elchupathingy13-May-10 3:54 
GeneralRe: Selecting all coordinates withing a distance Pin
Chris Meech13-May-10 4:22
Chris Meech13-May-10 4:22 
GeneralRe: Selecting all coordinates withing a distance Pin
David Skelly13-May-10 4:37
David Skelly13-May-10 4:37 
GeneralRe: Selecting all coordinates withing a distance Pin
Jeremy Hutchinson18-May-10 5:17
professionalJeremy Hutchinson18-May-10 5:17 
AnswerRe: Selecting all coordinates withing a distance Pin
Bernhard Hiller13-May-10 23:10
Bernhard Hiller13-May-10 23:10 
GeneralRe: Selecting all coordinates withing a distance Pin
Bernhard Hiller13-May-10 23:28
Bernhard Hiller13-May-10 23:28 
GeneralRe: Selecting all coordinates withing a distance Pin
Member 35753717-May-10 11:40
Member 35753717-May-10 11:40 
GeneralHow to sequence a loop Pin
TheNexpert6-May-10 23:10
TheNexpert6-May-10 23:10 
GeneralRe: How to sequence a loop Pin
riced6-May-10 23:51
riced6-May-10 23:51 
GeneralRe: How to sequence a loop Pin
Jeroen De Dauw7-May-10 0:43
Jeroen De Dauw7-May-10 0:43 
GeneralRe: How to sequence a loop Pin
Omar Gameel Salem13-May-10 13:55
professionalOmar Gameel Salem13-May-10 13:55 
GeneralRe: How to sequence a loop Pin
David Skelly7-May-10 2:09
David Skelly7-May-10 2:09 
GeneralRe: How to sequence a loop Pin
OriginalGriff7-May-10 3:48
mveOriginalGriff7-May-10 3:48 
GeneralRe: How to sequence a loop Pin
Sebastian Br.11-May-10 4:11
Sebastian Br.11-May-10 4:11 
GeneralRe: How to sequence a loop Pin
Paulo Zemek7-May-10 10:59
Paulo Zemek7-May-10 10:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.