Welcome Guest, Not a member yet? Register   Sign In
Limiting results to closest one of each type using datamapper
#4

[eluser]WanWizard[/eluser]
Assuming the $postlist is in order of distance, you could probably generate a SELECT CASE, where you compare the selected id with the value in the array assign an index value to a custom column you can order on.

Something like
Code:
// assume this is the array
$postlist = array( 0 => 12, 1 => 33, 2 => 6);

$case = 'index AS SELECT CASE `id`';

foreach ($postlist as $key => $value)
{
   $case .= ' WHEN '.$value.' THEN '.$key;
}
$case .= ' ELSE 0';

Just append it to the SELECT, and order by index ASC.


Messages In This Thread
Limiting results to closest one of each type using datamapper - by El Forum - 05-14-2012, 01:04 PM



Theme © iAndrew 2016 - Forum software by © MyBB