1

problems with a lot of users have the names of long in who liked for this Story So How can I sort users by number of published links in who voted.

in libs/htm1.php

function who_voted($storyid, $avatar_size){
// this returns who voted for a story
// eventually add support for filters (only show friends, etc)  
global $db;
if (!is_numeric($storyid)) die();

$sql = 'SELECT ' . table_votes . '.*, ' . table_users . '.* FROM ' . table_votes . ' INNER JOIN ' . table_users . ' ON ' . table_votes . '.vote_user_id = ' . table_users . '.user_id WHERE (((' . table_votes . '.vote_value)>0) AND ((' . table_votes . '.vote_link_id)='.$storyid.') AND (' . table_votes . '.vote_type= "links")) AND user_level<>"god" AND user_level<>"Spammer"';
//echo $sql;
$voters = $db->get_results($sql);
$voters = object_2_array($voters);
foreach($voters as $key => $val){
    $voters[$key]['Avatar_ImgSrc'] = get_avatar($avatar_size, "", $val['user_login'], $val['user_email']);
}

return $voters;

I found these lines in topusers.php, but not for a friendly experience in writing function correctly

    case 2: // sort users by number of published links
    $select = "SELECT user_id, count(*) as count ";
    $from_where = " FROM " . table_links . ", " . table_users . " WHERE  link_status = 'published' AND link_author=user_id AND user_level NOT IN ('god','Spammer') AND (user_login!='anonymous' OR user_lastip) GROUP BY link_author";
    $order_by = " ORDER BY count DESC ";
    break;
Mazen
  • 11
  • 2
  • This looks pretty nasty... Looks like 10yrs old code with some attempts to introduce objects there but still only with *functional-programmed* body making the life a little bit easier when the `blobal` was introduced... How can You sort by count of published links when You do not even count published links by user? In You second query (which really needs some refactoring!) instead of counting all rows, count only links for user and afterwards You can sort by this results... – shadyyx Dec 11 '13 at 12:30

0 Answers0