Math Php question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

mintedjo
Forum Contributor
Posts: 153
Joined: Wed Nov 19, 2008 6:23 am

Re: Math Php question

Post by mintedjo »

VladSun wrote:
mintedjo wrote:
VladSun wrote: ... But your expression is wrong ;) It should be

Code: Select all

ABS(pxls.x - other_pxls.x) + ABS(pxls.y - other_pxls.y)
I know, I followed up with a post correcting that.
Sorry, I didn't see it.
It's ok, we all make mistakes ;-)
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Math Php question

Post by onion2k »

mintedjo wrote:It's ok, we all make mistakes ;-)
I don't.

:mrgreen:
mintedjo
Forum Contributor
Posts: 153
Joined: Wed Nov 19, 2008 6:23 am

Re: Math Php question

Post by mintedjo »

onion2k wrote:
mintedjo wrote:It's ok, we all make mistakes ;-)
I do...

:mrgreen:
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Math Php question

Post by VladSun »

[sql]SELECT    pxls.x,    pxls.y,    (      SELECT        sum(abs(pxls.x - other_pxls.x) + abs(pxls.y - other_pxls.y))      FROM        pxls AS other_pxls    ) AS distance  FROM    pxls [/sql]
This query executes in 2.51 sec, but no "ORDER BY distance" is applied. So, you have 9'000'000 result records and you need to find MAX and MIN.
But ...
[sql]SELECT    pxls.x,    pxls.y,    (      SELECT        sum(abs(pxls.x - other_pxls.x) + abs(pxls.y - other_pxls.y))      FROM        pxls AS other_pxls    ) AS distance  FROM    pxls  ORDER BY distanceLIMIT 1[/sql]
is very, very slow.
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Math Php question

Post by VladSun »

onion2k wrote:
mintedjo wrote:It's ok, we all make mistakes ;-)
I don't.

:mrgreen:
I will be waiting for you to make one :twisted:
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply