You are here: Re: creating a cumulative total column, but not in sequence « PHP Programming Language « IT news, forums, messages
Re: creating a cumulative total column, but not in sequence

Posted by Ivαn Sαnchez Ortega on 01/01/08 02:38

mantrid wrote:

> I am particularly puzzled by what the function [...]
> is doing exactly. Particularly where argument $b comes from, and how it
> and the returned values -1,0 and 1 are affecting the ordering of the
> array.
[...]
> If anyone wants to explain this to me in simple english I'd be grateful.
> If not, no worries Im just glad it works. Been on this for 4 days now.

I could explain, but I'm growing a bit worn out by this loooong thread. And
I'd give you a headache too :-P

So: grab the nearest book on algorithmics, and open it up on the chapter
about sorting algorithms. Every sort algorithm depends on a comparison
function, to know if a item on the soon-to-be-sorted-out-list is "bigger"
or "smaller" than other item.

Really, do grab a book on algorithmics.



BTW, my solution was along the lines of *not* touching the array indexes and
declaring the comparison function something like this:

function usort_cmp($a, $b)
{
return ($a['date'] > $b['date'])
}

Reason behind this: you're comparing arrays (a set of id, date, companyid,
price, etc etc). One of those arrays is bigger than the other if the date
of the first array is bigger than the date of the second array.

Got the idea?



> Ever heard the one where you give a group of monkeys pens and paper and
> given enough time they will write the complete works of shakespere.

No, you're wrong. It's "old typewriters" ;-)

http://en.wikipedia.org/wiki/Infinite_monkey_theorem

--
----------------------------------
IvΓ‘n SΓ‘nchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

Proudly running Debian Linux with 2.6.22-3-amd64 kernel, KDE 3.5.8, and PHP
5.2.4-2 generating this signature.
Uptime: 03:28:40 up 39 days, 13:44, 4 users, load average: 0.53, 0.79,
0.77

 

Navigation:

[Reply to this message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация