Best way to sort arrays



Hi,

On my page I oftend find myself presenting my data like this

- all entries
1 - first (last modified)
2 - second
3 - last

- last entries
3 - last

- last modified
1 - first (last modified)

I have found a couple of ways to solve this

The first is 3 different queries
$allentries=$db::select('SELECT * FROM entries')
$lastentries=$db::select('SELECT * FROM entries ORDER BY id DESC LIMIT 5')
$lastmodefiedentries=$db::select('SELECT * FROM entries ORDER BY modefied DESC limit 5')

$allentries=$db::select('SELECT * FROM entries')
foreach($allentries as $val)
{
//
$lastentries[$val['id']]=$val;
$lastmodefiedentries[$val['modefied']]
}
// sort by id
krsort($lastentries)

// sort by modefied
krsort($lastmodefiedentries)

// etc

But I cant help wondering there should be a more efficient way to solve this.

In the first solution I use 2 extra queries and in the last soution I use more system resources and it isn't really reusable.

Anyone know a better way ?

Floortje

.



Relevant Pages

  • Re: Fantasy Books not set in pseudo-Europe
    ... looking for this sort of thing and haven't read those, ... you have to go to the entries on the 1001 Nights and on "Persia" ... <Wheel of the Infinite> ... Fantasy rooted in no particular Earth historical culture is not, ...
    (rec.arts.sf.written)
  • How to sort the variable length objects in Lexicographical order?
    ... I am involved in the Agent development for providing the support for ... about the lexicographic ordering of the table entries with respect to ... Because we need to sort the connection table based on four parameters ...
    (comp.protocols.snmp)
  • Re: What is the fastest way to determine if folder has subfolders or not!?
    ... | This sort of stuff does work very nicely, and is a good way of storing ... in binary tree search on 6000 entries would take 12 steps. ... for faster getting of free units, and if there is none free, using last unit offset + 1)... ... I sew VMWare has sdk for their disk format maybe beter idea would be to use their disk driver and sdk for such job. ...
    (microsoft.public.vb.winapi)
  • Re: read directory in alpha order
    ... I generally do this sort of thing in python although one could do ... for entry in entries: ...
    (comp.unix.sco.programmer)
  • Re: sorting data
    ... Now sort by the min date field with a secondary sort of Product number and a ... > (there are other columns representing information that is irrelevant) ... > The report contains several hundred rows of entries. ...
    (microsoft.public.excel)