These are just some ideas - not sure which one would be more
efficient:

$order = array();
foreach ($topLinks as $linkId) {
  $order[] = '(Link.id='.$linkId.') DESC';
}
... = $this->Link->find('all', array(
  'conditions' => ...,
  'order' => $order
));


[or]

$coef = 1;
$expr = array();
for($i=count($topLinks)-1; $i>=0; --$i) {
  $expr[] = $coef . '* (Link.id='.$topLinks[$i].')';
}
$expr = '('.implode('+', $expr) . ') AS position';

... = $this->Link->find('all', array(
  'conditions' => ...,
  'fields' => 'Link.*, ' . $expr,
  'order' => 'position ASC'
));

hth
grigri


On Jun 9, 8:15 am, Abhimanyu Grover <[EMAIL PROTECTED]> wrote:
> Hey,
>
> This is not Cake specific, but just posting here as I think this will
> be useful for others as well. Here's my code:
>
>                         $topLinks = $this->Vote->getTopRated();
>                         $this->set('links', 
> $this->Link->findAll(array('Link.id'=>
> $topLinks, 'Link.status'=>UC_STATUS_APPROVED)));
>
> In first line, I'm trying to get Id's of all top rated links - which
> comes from a bit complex algorithm.
> In second line, I pass on those ids to findAll() which creates sql
> statement like this:
>
> WHERE `Link`.`id` IN (1, 5, 7, 4, 3)
>
> Now problem is, I need them in same order as I've sent them in IN(..)
> but mysql returns them ordering by id. i.e. 1, 3, 4, 5, 7
>
> I've tried appending Order by NULL, but it wouldn't work. Can anyone
> help?
>
> Thanks,
> Abhimanyu Grover
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to