query("SELECT id,text from categories where id='$id'")->fetch(PDO::FETCH_ASSOC);
if (empty($row['id'])) {
$page = array (
'meta_title' => 'Not Found',
'page_title' => 'Category Not Found',
'content' => '
The category ID you requested was not found.
',
'lastsearch' => $_SESSION['lastsearch']
);
show_page($page);
exit;
}
$page['page_title'] = "Category : " . $row['text'];
//$count = 0;
$sql_limit = '';
if ($user['level'] < 3) {
$sql_limit = "and companies.status='1'";
}
$usedcomps = array();
foreach($db->query("SELECT categorized.compid as compid, companies.cname as cname, status from categorized,companies where categorized.catid='$id' and companies.id=compid $sql_limit")->fetchAll(PDO::FETCH_ASSOC) as $row) {
$results[$row['compid']] = $row['cname'];
$status[$row['compid']] = $row['status'];
}
asort($results);
$numcomps = count($results);
$onehalf = ceil($numcomps/2);
$cnt = 1;
$list = "\n
\n";
foreach ($results as $key => $value) {
$style = '';
if ($status[$key] == '0') {
$style = 'disabled';
}
$list .= "
\n";
if ($numcomps > 5 && $cnt == $onehalf) {
$list .= "
\n
\n";
}
$cnt++;
//$count++;
}
$list .= "
\n
\n
\n";
}
else {
$usedcats = array();
foreach($db->query("SELECT DISTINCT categories.id as id, categories.text FROM categories,categorized where categories.id=categorized.catid order by categories.text")->fetchAll(PDO::FETCH_ASSOC) as $row) {
$usedcats[$row['id']] = $row['text'];
}
$numcats = count($usedcats);
$onehalf = ceil($numcats/2);
$cnt = 1;
$list = "\n
\n";
foreach($usedcats as $key => $val) {
$list .= "
\n";
if ($cnt == $onehalf) {
$list .= "
\n
\n";
}
$cnt++;
}
$list .= "
\n
\n
\n";
$page['page_title'] = "Categories";
}
if (!empty($numcomps)) {
$word = 'companies';
if ($numcomps == 1) {
$word = 'company';
}
$numcomps = "$numcomps $word
\n";
}
if (!empty($numcats)) {
$word = 'categories';
if ($numcats == 1) {
$word = 'category';
}
$numcats = "$numcats $word
\n";
}
$page['meta_title'] = strip_tags($page['page_title']);
$page['content'] = $numcomps . $numcats . $list;
show_page($page);
exit;
?>