Order results

Metafriki - March 7, 2009 - 04:48
Project:Word count
Version:5.x-1.0
Component:User interface
Category:feature request
Priority:normal
Assigned:CrookedNumber
Status:closed
Description

Been capable of sorting results (ASC, DESC) by total wordcount or nº of comment would be great. I hardcoded a sorting method for total (DESC) in wordcount_show_count() function this way:

foreach ($row as $k=>$v) {
$row[$k]['avg_post'] = ($row[$k]['posts']) ? number_format($row[$k]['num_words_post']/$row[$k]['posts'], 1) : 0;
$row[$k]['avg_comment'] = ($row[$k]['comments']) ? number_format($row[$k]['num_words_comment']/$row[$k]['comments'],1) : 0;
$row[$k]['total'] = $row[$k]['num_words_post'] + $row[$k]['num_words_comment'];
}

// NEW CODE

function cmp($a, $b) {
if ($a["total"] == $b["total"]) {
return 0;
} else {
return ($a["total"] > $b["total"]) ? -1 : 1;
}
}

usort($row, "cmp");

// END OF NEW CODE

$header = array(
array ('data' => 'id'),
...

Not going to win a PHP coding contest, but works for me

#1

CrookedNumber - September 21, 2009 - 20:58
Assigned to:Anonymous» CrookedNumber
Status:active» fixed

Thanks for the ideas, Metafriki.

This has (essentially) been accomplished in 6-1.1, using the tablesorter jquery plugin.

http://drupal.org/node/583868

#2

System Message - October 5, 2009 - 21:00
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.