praxedis
06-17-2005, 11:52 AM
Recordset
a | 8
a | 9
b | 8
c | 8
d | 8
d | 9
I want to sort and bring back this:
a | 9
b | 8
c | 8
d | 9
In other words, filter out the 8s if they already have 9s.
Can anyone point me in the right direction?
the--dud
06-17-2005, 02:03 PM
collect all the a's, see if it has nine, if it does see if it has eight, if it does remove 8.
repeate for each letter...
SpiralWebs
06-17-2005, 02:28 PM
use recursion...
what language are you doing this in?
maxymizer
06-17-2005, 02:35 PM
Is the resultset coming from a database or how is the recordset populated?
In SQL there's select DISTINCT(fieldname) that filters out the query.
On the other hand, php solution would be array_unique().
You can look up function specifics at www.php.net/array_unique
carguy84
06-18-2005, 02:32 AM
what about "Select max(columnA) from table, order by columnA ASC"?
VolkNet
06-18-2005, 03:07 AM
Originally posted by SpiralWebs
use recursion...
what language are you doing this in?
Yea, use a function that calls itself basically in a loop until it finds it. If it goes through all the codes and gives none then return the 8.
Hope that make sense.
maxymizer
06-18-2005, 04:20 AM
Originally posted by carguy84
what about "Select max(columnA) from table, order by columnA ASC"?
That would return only 1 record which makes your example useless in this case. That's why you have DISTINCT keyword.
Also, using array_unique when dealing with arrays makes recursion unnecessary and pointless when dealing with such problems.
carguy84
06-18-2005, 01:48 PM
oops, that's what you get for giving drunken advice, lol. forgot the "group by columnA" part :)
Look I think whatever you get the data from, simply using PHP's built-in array_flip this way:
$array=array_flip(array_flip($array));
will result in a new array with no duplicates.
HTH
Omar