All pastes #241853 Raw Edit

Anonymous

public text v1 · immutable
·published 2006-11-06 18:25 UTC
rendered paste body
    $output .= _mymodule_alphabar('vital_betegseg/%d', db_rewrite_sql("SELECT DISTINCT (LEFT(title,1)) AS title FROM {node} WHERE type = 'vital_betegseg'"));

function _mymodule_alphabar($path_mask, $sql, $params = array()) {
  if (!$links = cache_get('mymodule_alphabar')) {
    $result  = db_query($sql, $params);
    $chars = array();
    while ($char = db_fetch_object($result)) {
      $chars[ucfirst($char->title)] = 1;
    }
    $links = array();
    for ($i = 65; $i < 91; $i++) {
      $c = chr($i);
      if (isset($chars[$c])) {
        $links[] = l($c, sprintf($path_mask, $i));
      }
      else {
        $links[] = $c;
      }
    }
    $links = theme('item_list', $links);
    cache_set('mymodule_alphabar', $links, CACHE_TEMPORARY);
  }
  else {
    $links = $links->data;
  }
  return $links;
}