<?php

/* No empty dropdowns please */
if ($field != '' AND $id != '') {
	$out = wp_cache_get( 'wct_select_'.$field , 'wct');
	if ($out == false) {
		$limit = (integer)$limit;
		if ($limit <= '0') { $limit = '1'; }
		$qry = $wpdb->get_results("SELECT `".mres($field)."` AS `item`,count(".mres($field).") AS `anz`  FROM `".$wpdb->prefix."wct".mres($id)."` GROUP BY `".mres($field)."` ORDER BY `anz` DESC LIMIT ".$limit.";");
		if (count($qry) >= '1') {
			$out = "<select onChange=\"selector('".$field."')\" style=\"font-weight: bold;\" id=\"wctdrop_".$field."\" name=\"wctdrop_".$field."\"><option style=\"font-weight: bold;\" value=\"NULL\">".$maintext."</option>";
			foreach ($qry as $row) {
				
				$out .= "<option style=\"font-weight: normal;\" value=\"".$row->item."\" ";
				if (($_GET['wctdrop'] == $row->item AND $row->item != '') OR ($_GET['wctdrof'] != '' AND $_GET['wctdrop'] != 'NULL' AND $row->item == '')) { $out .= " selected"; }
				$out .= ">";
				if ($row->item == '') { $out .= "-- ".__('Empty','wct')." --"; } else { $out .= $row->item; }
 
				$out .= " (".$row->anz.")</option>";
			}
			$out .= "</select>";
		}
		/* If field not existing or no options to dropdown, no cache! */
		if ($out != '') { wp_cache_set( 'wct_select'.$field, $out, 'wct', $this->settings['wct_cachetime']); $include_js = '1'; }
	}
}

?>