douhu2890
2015-09-14 07:51
浏览 6
已采纳

drupal 7类别和计数列表

Making my code but, not what I want

$query = db_select('field_data_field_job','f');
$query->distinct('field_job');
$query->fields('f',array('field_job_value'));
$query->isNotNull('field_job_value');
$query->orderBy('field_job_value', 'ASC');
$items = $query->execute()->fetchAll();
$node = node_load($node->nid);
$field = field_info_field('field_job');
echo '<ul class="chapter-list">';
foreach($items as $key=>$value) {
$item = $value->field_job_value;
$label = $field['settings']['allowed_values'][$item];
$labels = $field['settings']['allowed_values'][$item];
echo '<li class=""><a href="'.$base_url.'/jobs/'.$item.'">'.$label.' '.$labels.'</a></li>';
}
echo '</ul>';

list of construction workers

  Nurse 
  Doctor

I want to be, category list.

Nurse (5)
Doctor (4)
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dsykx64220 2015-09-14 14:28
    已采纳

    completed :)

    foreach($items as $key=>$value) {
    $item = $value->field_job_value;
    $label = $field['settings']['allowed_values'][$item];
    $queryItem = db_select('field_data_field_job','f');
    $queryItem->fields('f',array('field_job_value'));
    $queryItem->isNotNull('field_job_value');
    $queryItem->condition('field_job_value', $item, '=');
    $count_query = $queryItem->countQuery()->execute()->fetchField();
    
    echo '<li class=""><a href="'.$base_url.'/jobs/'.$item.'">'.$label.' ('.$count_query.') </a></li>';
    }
    echo '</ul>';
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题