I have a piece of code that is supposed to grab categories, sort them alphabetically (they're available in several languages) as well as return a count for each of them. The problem is, for some reason the count isn't returned at all. I feel like the problem is somewhere around this line:
(($categoryCounter) ? '<span class="cnt">(' . $categoryCounter . ')</span>' : '') .
I tried changing it to $categoryCounter[$key] or something but that didn't work. Unfortunately my PHP skills are not good enough to find out what I'm doing wrong. If anyone can see what I'm obviously doing wrong I'd greatly appreciate some help :)
Here is the complete code;
while ($cat_details = $db->fetch_array($sql_select_categories))
{
$categoryCounter = (COUNT_CATS == 1 && !empty($src_details['keywords_search'])) ? $cat_counter[$cat_details['category_id']] : $cat_details['items_counter'];
if ($categoryCounter > 0 || COUNT_CATS == 0) {
$cat_array[$cat_details['category_id']]["name"]=$category_lang[$cat_details['category_id']];
}
}
if (is_array($cat_array)) {
asort($cat_array);
foreach($cat_array as $key => $value){
$output .= '<tr> '.
' <td class="contentfont"><a href="' . $subcat_link . '">' . $category_lang[$key] . '</a> '.
(($categoryCounter) ? '<span class="cnt">(' . $categoryCounter . ')</span>' : '') .
' </td> '.
'</tr> ';
}
}
$categoryCounter
before the for loop or the if statement, to see what value it holds? Do a simple debug run.