Datenbankabfrage
Verfasst: 21.06.2007, 09:03
Hallo
Ich habe ein kleines Problem, und für die Lösung würde ich einen Featured Link von Deutscher-Index.info anbieten.
In einem Script wird in einer Kategorie die ID der übergeordneten Kategorie so angezeigt: {$this_cat['parent_cat_id']}. Jetzt möchte ich mir dazu aber den Namen eben dieser Kategorie auch anzeigen lassen.
In der aktuellen Kategorie wird die aktuelle ID und der Name so angezeigt: {$row['cat_id']} und {$row['name']}.
Jetzt brauche ich eine Abfrage der DB für den Namen der parent_cat und weis nicht wie
Die ID der Kategorie wird in einer der beiden unteren php Dateien abgefragt.
Vielen Dank
show_cat.php
<?php
require_once './global.php';
$tr = 0;
$show_cat_cats = "";
$show_cat_pagelink = "";
if (!isset($_GET['cat_id']) || $_GET['cat_id'] == 0) {
header('location:./index.php');
exit;
}
$this_cat = $db->query_fetch("SELECT cat_id, name, description, parent_cat_id FROM ".$prefix."cats WHERE cat_id = '".intval($_GET['cat_id'])."'");
if (!$this_cat['cat_id']) {
header('location:./index.php');
exit;
}
// Pagelink
if (!isset($_GET['page'])) {
$page = 1;
} else {
$page = intval($_GET['page']);
if ($page < 1) {
$page = 1;
}
}
$start = ($page - 1) * $options['pagelink'];
$count = $db->query_fetch("SELECT count(*) as links FROM ".$prefix."links WHERE parent_cat_id = '".$this_cat['cat_id']."' AND (link_type = '1' OR link_type = '2' OR link_type = '4') AND activated = '1' AND deactivated = '0'");
if ($count['links'] > $options['pagelink']) {
$pages = $count['links'] / $options['pagelink'];
if ($pages != floor($pages)) {
$pages = floor($pages) + 1;
}
for ($page_id = 1; $page_id <= $pages; $page_id++) {
$tpl->load('show_cat_pagelink', 'show_cat_pagelink_bit');
}
}
$title = 'Kategorie: '.$this_cat['name'];
// Unterkategorien
$result = $db->query("SELECT cat_id, name, description, links FROM ".$prefix."cats WHERE parent_cat_id = '".$this_cat['cat_id']."' ORDER BY name ASC");
while ($row = $db->fetch_array($result)) {
$new = $db->query_fetch("SELECT count(*) as count FROM ".$prefix."links WHERE parent_cat_id = '".$row['cat_id']."' AND date_entry >= '".(time() - 60 * 60 * 24 * $options['newlinks_img'])."' AND activated = '1' AND deactivated = '0'");
$tr++;
$tpl->load('show_cat_cats', 'show_cat_cat_bit');
}
// Sponsorlinks
$tr = 0;
$result = $db->query("SELECT l.link_id, l.name, l.description, l.link_type, l.button, l.banner, l.date_entry, l.clicks FROM ".$prefix."links AS l WHERE l.parent_cat_id = '".$this_cat['cat_id']."' AND l.link_type = '3' AND activated = '1' AND deactivated = '0' GROUP BY l.link_id");
while ($row = $db->fetch_array($result)) {
$row['name'] = htmlentities($row['name']);
$tr++;
$tpl->load('show_cat_sponsors', 'show_cat_sponsor_bit');
}
// Image Links
switch ($options['top_sort']) {
case 'alphabet':
$order_by = 'l.name ASC';
break;
case 'rate':
$order_by = 'avg_points DESC';
break;
case 'clicks':
$order_by = 'clicks DESC';
break;
}
$result = $db->query("SELECT l.link_id, l.name, l.description, l.link_type, l.image, l.date_entry, l.clicks, SUM(v.points) / COUNT(v.link_id) AS avg_points, COUNT(v.link_id) AS votes FROM ".$prefix."links AS l LEFT JOIN ".$prefix."votes AS v ON (l.link_id = v.link_id) WHERE l.parent_cat_id = '".$this_cat['cat_id']."' AND l.link_type = '4' AND activated = '1' AND deactivated = '0' GROUP BY l.link_id ORDER BY ".$order_by." LIMIT $start, ".$options['pagelink']);
while ($row = $db->fetch_array($result)) {
$row['date'] = $row['date_entry'];
$row['name'] = htmlentities($row['name']);
$row['description'] = htmlentities($row['description']);
$row['description'] = nl2br($row['description']);
$row['image'] = htmlentities($row['image']);
$row['date_entry'] = date('d.m.Y', $row['date_entry']);
$row['avg_points'] = number_format($row['avg_points'], 2, '.', '');
$tpl->load('show_cat_links', 'show_cat_link_bit');
}
// andere Links
switch ($options['normal_sort']) {
case 'alphabet':
$order_by = 'l.name ASC';
break;
case 'rate':
//$order_by = 'avg_points DESC';
$order_by = 'votes DESC';
break;
case 'clicks':
$order_by = 'clicks DESC';
break;
}
$result = $db->query("SELECT l.link_id, l.name, l.description, l.link_type, l.image, l.date_entry, l.clicks, SUM(v.points) / COUNT(v.link_id) AS avg_points, COUNT(v.link_id) AS votes FROM ".$prefix."links AS l LEFT JOIN ".$prefix."votes AS v ON (l.link_id = v.link_id) WHERE l.parent_cat_id = '".$this_cat['cat_id']."' AND (l.link_type = '1' OR l.link_type = '2') AND activated = '1' AND deactivated = '0' GROUP BY l.link_id ORDER BY l.link_type DESC, ".$order_by." LIMIT $start, ".$options['pagelink']);
while ($row = $db->fetch_array($result)) {
$row['date'] = $row['date_entry'];
$row['name'] = htmlentities($row['name']);
$row['description'] = htmlentities($row['description']);
$row['description'] = nl2br($row['description']);
$row['image'] = htmlentities($row['image']);
$row['date_entry'] = date('d.m.Y', $row['date_entry']);
$row['avg_points'] = number_format($row['avg_points'], 2, '.', '');
$tpl->load('show_cat_links', 'show_cat_link_bit');
}
$tpl->load('content', 'show_cat');
$tpl->output();
?>
global.php
<?php
error_reporting(0);
if (extension_loaded('zlib') && headers_sent()) {
ob_start('ob_gzhandler');
} else {
ob_start();
}
$_POST = $HTTP_POST_VARS;
$_GET = $HTTP_GET_VARS;
$_REQUEST = array_merge($_GET, $_POST);
$_COOKIE = $HTTP_COOKIE_VARS;
$_SERVER = $HTTP_SERVER_VARS;
if (!get_magic_quotes_gpc()) {
$_POST = addslashes_array($_POST);
$_GET = addslashes_array($_GET);
$_REQUEST = addslashes_array($_REQUEST);
$_COOKIE = addslashes_array($_COOKIE);
}
@set_magic_quotes_runtime(0);
// SECURITY: emulates register_globals = off
foreach (array_merge($_GET, $_POST, $_COOKIE) as $key) {
unset($$key);
}
// connect to the database...
require './acp/inc/db_config.php';
require './acp/inc/class_database.php';
$db = new database;
$db->host = $db_host;
$db->user = $db_user;
$db->pass = $db_pass;
$db->db = $db_name;
$db->prefix = $prefix;
$db->connect();
require './acp/inc/class_template.php';
$tpl = new template;
$tpl->templatedir = './templates/';
$result = $db->query("SELECT name, value FROM ".$prefix."options");
while ($row = $db->fetch_array($result)) {
$options[$row['name']] = $row['value'];
}
// abgelaufene Links (Mail)
$result = $db->query("SELECT link_id, name, email FROM ".$prefix."links WHERE activated = '1' AND deactivated = '0' AND date_activate < '".(time() - 60*60*24*($options['elapse']-7))."' AND mail_send = '0'");
while ($row = $db->fetch_array($result)) {
$text = "Hallo,
Ihr Link ".$row['name']." (Link-ID ".$row['link_id'].") bei ".$options['url']." läuft in 7 Tagen
ab. Um ihn um weitere ".$options['elapse']." Tage zu aktivieren, müssen Sie sich einmal unter \"Eintrag ändern\" einloggen.";
mail($row['email'], "Ihr Link läuft in 7 Tagen ab", $text, "From: ".$options['email']."\r\nReply-To: ".$options['email']."\r\n");
$db->query("UPDATE ".$prefix."links SET mail_send = '1' WHERE link_id = '".$row['link_id']."'");
}
// abgelaufene Links
$result = $db->query("SELECT * FROM ".$prefix."links WHERE activated = '1' AND deactivated = '0' AND date_activate < '".(time() - 60*60*24*$options['elapse'])."'");
while ($row = $db->fetch_array($result)) {
switch ($options['elapse_action']) {
case 'del':
$aktion = "gelöscht";
$db->query("DELETE FROM ".$prefix."links WHERE link_id = '".$row['link_id']."'");
// alte Kat Link abziehen
$parent_cat_id = $row['parent_cat_id'];
do {
$parent_cat = $db->query_fetch("SELECT * FROM ".$prefix."cats WHERE cat_id = '".$parent_cat_id."'");
$db->query("UPDATE ".$prefix."cats SET links = links - 1 WHERE cat_id = '".$parent_cat_id."'");
$parent_cat_id = $parent_cat['parent_cat_id'];
}
while ($parent_cat_id != 0);
break;
case 'deactivate':
$aktion = "deaktiviert";
$db->query("UPDATE ".$prefix."links SET deactivated = '1' WHERE link_id = '".$row['link_id']."'");
// alte Kat Link abziehen
$parent_cat_id = $row['parent_cat_id'];
do {
$parent_cat = $db->query_fetch("SELECT * FROM ".$prefix."cats WHERE cat_id = '".$parent_cat_id."'");
$db->query("UPDATE ".$prefix."cats SET links = links - 1 WHERE cat_id = '".$parent_cat_id."'");
$parent_cat_id = $parent_cat['parent_cat_id'];
}
while ($parent_cat_id != 0);
break;
case 'standard':
$aktion = "auf 'Standard' gesetzt";
$db->query("UPDATE ".$prefix."links SET link_type = '1' WHERE link_id = '".$row['link_id']."'");
break;
}
//Mail an Admin
$admin_notify = "Ein Link wurde wegen Ablauf $aktion:
Link-Name: $row[name]
URL: $row[url]
Beschreibung: ".htmlentities($row['description'])."
Firma: $row[company]
Name: $row[person]
Straße: $row[street]
Ort: $row[plz] $row[city]
E-Mail: $row[email]
Zahlungsweise: $row[payment]
Bank: $row[bank]
BLZ: $row[blz]
Konto: $row[konto]";
mail($options['email'], "Link wurde wegen Ablauf $aktion", $admin_notify, "From: ".$options['email']."\r\nReply-To: ".$options['email']."\r\n");
}
// neue Links
if ($options['show_newlinks'] == 1) {
$box_newlinks = "";
$result = $db->query("SELECT link_id, name FROM ".$prefix."links WHERE activated = '1' AND deactivated = '0' ORDER BY date_entry DESC LIMIT 0,".intval($options['show_newlinks_limit']));
while ($row = $db->fetch_array($result)) {
$tpl->load('box_newlinks', 'box_newlinks_bit');
}
}
// Partner
if ($options['show_partner'] == 1) {
$box_partner = "";
$result = $db->query("SELECT * FROM ".$prefix."partner");
while ($row = $db->fetch_array($result)) {
$tpl->load('box_partner', 'box_partner_bit');
}
}
include './ad.php';
function get_cats($cat_cache, $parent_cat_id = 0, $depth = 0) {
global $children, $tab, $cat, $tpl;
if (is_array($cat_cache)) {
foreach ($cat_cache as $key => $cat) {
if ($cat['parent_cat_id'] == $parent_cat_id) {
$tab = str_repeat('--', $depth);
$tpl->load('cat_list', 'cat_list_bit');
if (isset($children[$cat['cat_id']]) && $children[$cat['cat_id']] == 1) {
get_cats($cat_cache, $cat['cat_id'], $depth + 1);
}
}
}
}
}
function addslashes_array($array) {
foreach ($array as $key => $value) {
$array[$key] = addslashes($value);
}
return $array;
}
// ab hier Update
srand ((double)microtime()*1000000);
if (rand(0,50) == 25) {
$result = $db->query("SELECT cat_id, name, parent_cat_id FROM ".$prefix."cats");
while ($row = $db->fetch_array($result)) {
$cache_cats[$row['cat_id']] = $row;
}
$result = $db->query("SELECT parent_cat_id FROM ".$prefix."links");
while ($row = $db->fetch_array($result)) {
$parent_cat_id = $row['parent_cat_id'];
if (isset($linkcount[$parent_cat_id])) {
$linkcount[$parent_cat_id]++;
} else {
$linkcount[$parent_cat_id] = 1;
}
while ($cache_cats[$parent_cat_id]['parent_cat_id'] != 0) {
// hat parent-cat => inkrementieren
if (isset($linkcount[$cache_cats[$parent_cat_id]['parent_cat_id']])) {
$linkcount[$cache_cats[$parent_cat_id]['parent_cat_id']]++;
} else {
$linkcount[$cache_cats[$parent_cat_id]['parent_cat_id']] = 1;
}
$parent_cat_id = $cache_cats[$parent_cat_id]['parent_cat_id'];
}
}
foreach ($cache_cats as $key => $value) {
if (isset($linkcount[$value['cat_id']])) {
$db->query("UPDATE ".$prefix."cats SET links='".$linkcount[$value['cat_id']]."' WHERE cat_id = '".$value['cat_id']."'");
}
}
}
?>
Ich habe ein kleines Problem, und für die Lösung würde ich einen Featured Link von Deutscher-Index.info anbieten.
In einem Script wird in einer Kategorie die ID der übergeordneten Kategorie so angezeigt: {$this_cat['parent_cat_id']}. Jetzt möchte ich mir dazu aber den Namen eben dieser Kategorie auch anzeigen lassen.
In der aktuellen Kategorie wird die aktuelle ID und der Name so angezeigt: {$row['cat_id']} und {$row['name']}.
Jetzt brauche ich eine Abfrage der DB für den Namen der parent_cat und weis nicht wie

Die ID der Kategorie wird in einer der beiden unteren php Dateien abgefragt.
Vielen Dank
show_cat.php
<?php
require_once './global.php';
$tr = 0;
$show_cat_cats = "";
$show_cat_pagelink = "";
if (!isset($_GET['cat_id']) || $_GET['cat_id'] == 0) {
header('location:./index.php');
exit;
}
$this_cat = $db->query_fetch("SELECT cat_id, name, description, parent_cat_id FROM ".$prefix."cats WHERE cat_id = '".intval($_GET['cat_id'])."'");
if (!$this_cat['cat_id']) {
header('location:./index.php');
exit;
}
// Pagelink
if (!isset($_GET['page'])) {
$page = 1;
} else {
$page = intval($_GET['page']);
if ($page < 1) {
$page = 1;
}
}
$start = ($page - 1) * $options['pagelink'];
$count = $db->query_fetch("SELECT count(*) as links FROM ".$prefix."links WHERE parent_cat_id = '".$this_cat['cat_id']."' AND (link_type = '1' OR link_type = '2' OR link_type = '4') AND activated = '1' AND deactivated = '0'");
if ($count['links'] > $options['pagelink']) {
$pages = $count['links'] / $options['pagelink'];
if ($pages != floor($pages)) {
$pages = floor($pages) + 1;
}
for ($page_id = 1; $page_id <= $pages; $page_id++) {
$tpl->load('show_cat_pagelink', 'show_cat_pagelink_bit');
}
}
$title = 'Kategorie: '.$this_cat['name'];
// Unterkategorien
$result = $db->query("SELECT cat_id, name, description, links FROM ".$prefix."cats WHERE parent_cat_id = '".$this_cat['cat_id']."' ORDER BY name ASC");
while ($row = $db->fetch_array($result)) {
$new = $db->query_fetch("SELECT count(*) as count FROM ".$prefix."links WHERE parent_cat_id = '".$row['cat_id']."' AND date_entry >= '".(time() - 60 * 60 * 24 * $options['newlinks_img'])."' AND activated = '1' AND deactivated = '0'");
$tr++;
$tpl->load('show_cat_cats', 'show_cat_cat_bit');
}
// Sponsorlinks
$tr = 0;
$result = $db->query("SELECT l.link_id, l.name, l.description, l.link_type, l.button, l.banner, l.date_entry, l.clicks FROM ".$prefix."links AS l WHERE l.parent_cat_id = '".$this_cat['cat_id']."' AND l.link_type = '3' AND activated = '1' AND deactivated = '0' GROUP BY l.link_id");
while ($row = $db->fetch_array($result)) {
$row['name'] = htmlentities($row['name']);
$tr++;
$tpl->load('show_cat_sponsors', 'show_cat_sponsor_bit');
}
// Image Links
switch ($options['top_sort']) {
case 'alphabet':
$order_by = 'l.name ASC';
break;
case 'rate':
$order_by = 'avg_points DESC';
break;
case 'clicks':
$order_by = 'clicks DESC';
break;
}
$result = $db->query("SELECT l.link_id, l.name, l.description, l.link_type, l.image, l.date_entry, l.clicks, SUM(v.points) / COUNT(v.link_id) AS avg_points, COUNT(v.link_id) AS votes FROM ".$prefix."links AS l LEFT JOIN ".$prefix."votes AS v ON (l.link_id = v.link_id) WHERE l.parent_cat_id = '".$this_cat['cat_id']."' AND l.link_type = '4' AND activated = '1' AND deactivated = '0' GROUP BY l.link_id ORDER BY ".$order_by." LIMIT $start, ".$options['pagelink']);
while ($row = $db->fetch_array($result)) {
$row['date'] = $row['date_entry'];
$row['name'] = htmlentities($row['name']);
$row['description'] = htmlentities($row['description']);
$row['description'] = nl2br($row['description']);
$row['image'] = htmlentities($row['image']);
$row['date_entry'] = date('d.m.Y', $row['date_entry']);
$row['avg_points'] = number_format($row['avg_points'], 2, '.', '');
$tpl->load('show_cat_links', 'show_cat_link_bit');
}
// andere Links
switch ($options['normal_sort']) {
case 'alphabet':
$order_by = 'l.name ASC';
break;
case 'rate':
//$order_by = 'avg_points DESC';
$order_by = 'votes DESC';
break;
case 'clicks':
$order_by = 'clicks DESC';
break;
}
$result = $db->query("SELECT l.link_id, l.name, l.description, l.link_type, l.image, l.date_entry, l.clicks, SUM(v.points) / COUNT(v.link_id) AS avg_points, COUNT(v.link_id) AS votes FROM ".$prefix."links AS l LEFT JOIN ".$prefix."votes AS v ON (l.link_id = v.link_id) WHERE l.parent_cat_id = '".$this_cat['cat_id']."' AND (l.link_type = '1' OR l.link_type = '2') AND activated = '1' AND deactivated = '0' GROUP BY l.link_id ORDER BY l.link_type DESC, ".$order_by." LIMIT $start, ".$options['pagelink']);
while ($row = $db->fetch_array($result)) {
$row['date'] = $row['date_entry'];
$row['name'] = htmlentities($row['name']);
$row['description'] = htmlentities($row['description']);
$row['description'] = nl2br($row['description']);
$row['image'] = htmlentities($row['image']);
$row['date_entry'] = date('d.m.Y', $row['date_entry']);
$row['avg_points'] = number_format($row['avg_points'], 2, '.', '');
$tpl->load('show_cat_links', 'show_cat_link_bit');
}
$tpl->load('content', 'show_cat');
$tpl->output();
?>
global.php
<?php
error_reporting(0);
if (extension_loaded('zlib') && headers_sent()) {
ob_start('ob_gzhandler');
} else {
ob_start();
}
$_POST = $HTTP_POST_VARS;
$_GET = $HTTP_GET_VARS;
$_REQUEST = array_merge($_GET, $_POST);
$_COOKIE = $HTTP_COOKIE_VARS;
$_SERVER = $HTTP_SERVER_VARS;
if (!get_magic_quotes_gpc()) {
$_POST = addslashes_array($_POST);
$_GET = addslashes_array($_GET);
$_REQUEST = addslashes_array($_REQUEST);
$_COOKIE = addslashes_array($_COOKIE);
}
@set_magic_quotes_runtime(0);
// SECURITY: emulates register_globals = off
foreach (array_merge($_GET, $_POST, $_COOKIE) as $key) {
unset($$key);
}
// connect to the database...
require './acp/inc/db_config.php';
require './acp/inc/class_database.php';
$db = new database;
$db->host = $db_host;
$db->user = $db_user;
$db->pass = $db_pass;
$db->db = $db_name;
$db->prefix = $prefix;
$db->connect();
require './acp/inc/class_template.php';
$tpl = new template;
$tpl->templatedir = './templates/';
$result = $db->query("SELECT name, value FROM ".$prefix."options");
while ($row = $db->fetch_array($result)) {
$options[$row['name']] = $row['value'];
}
// abgelaufene Links (Mail)
$result = $db->query("SELECT link_id, name, email FROM ".$prefix."links WHERE activated = '1' AND deactivated = '0' AND date_activate < '".(time() - 60*60*24*($options['elapse']-7))."' AND mail_send = '0'");
while ($row = $db->fetch_array($result)) {
$text = "Hallo,
Ihr Link ".$row['name']." (Link-ID ".$row['link_id'].") bei ".$options['url']." läuft in 7 Tagen
ab. Um ihn um weitere ".$options['elapse']." Tage zu aktivieren, müssen Sie sich einmal unter \"Eintrag ändern\" einloggen.";
mail($row['email'], "Ihr Link läuft in 7 Tagen ab", $text, "From: ".$options['email']."\r\nReply-To: ".$options['email']."\r\n");
$db->query("UPDATE ".$prefix."links SET mail_send = '1' WHERE link_id = '".$row['link_id']."'");
}
// abgelaufene Links
$result = $db->query("SELECT * FROM ".$prefix."links WHERE activated = '1' AND deactivated = '0' AND date_activate < '".(time() - 60*60*24*$options['elapse'])."'");
while ($row = $db->fetch_array($result)) {
switch ($options['elapse_action']) {
case 'del':
$aktion = "gelöscht";
$db->query("DELETE FROM ".$prefix."links WHERE link_id = '".$row['link_id']."'");
// alte Kat Link abziehen
$parent_cat_id = $row['parent_cat_id'];
do {
$parent_cat = $db->query_fetch("SELECT * FROM ".$prefix."cats WHERE cat_id = '".$parent_cat_id."'");
$db->query("UPDATE ".$prefix."cats SET links = links - 1 WHERE cat_id = '".$parent_cat_id."'");
$parent_cat_id = $parent_cat['parent_cat_id'];
}
while ($parent_cat_id != 0);
break;
case 'deactivate':
$aktion = "deaktiviert";
$db->query("UPDATE ".$prefix."links SET deactivated = '1' WHERE link_id = '".$row['link_id']."'");
// alte Kat Link abziehen
$parent_cat_id = $row['parent_cat_id'];
do {
$parent_cat = $db->query_fetch("SELECT * FROM ".$prefix."cats WHERE cat_id = '".$parent_cat_id."'");
$db->query("UPDATE ".$prefix."cats SET links = links - 1 WHERE cat_id = '".$parent_cat_id."'");
$parent_cat_id = $parent_cat['parent_cat_id'];
}
while ($parent_cat_id != 0);
break;
case 'standard':
$aktion = "auf 'Standard' gesetzt";
$db->query("UPDATE ".$prefix."links SET link_type = '1' WHERE link_id = '".$row['link_id']."'");
break;
}
//Mail an Admin
$admin_notify = "Ein Link wurde wegen Ablauf $aktion:
Link-Name: $row[name]
URL: $row[url]
Beschreibung: ".htmlentities($row['description'])."
Firma: $row[company]
Name: $row[person]
Straße: $row[street]
Ort: $row[plz] $row[city]
E-Mail: $row[email]
Zahlungsweise: $row[payment]
Bank: $row[bank]
BLZ: $row[blz]
Konto: $row[konto]";
mail($options['email'], "Link wurde wegen Ablauf $aktion", $admin_notify, "From: ".$options['email']."\r\nReply-To: ".$options['email']."\r\n");
}
// neue Links
if ($options['show_newlinks'] == 1) {
$box_newlinks = "";
$result = $db->query("SELECT link_id, name FROM ".$prefix."links WHERE activated = '1' AND deactivated = '0' ORDER BY date_entry DESC LIMIT 0,".intval($options['show_newlinks_limit']));
while ($row = $db->fetch_array($result)) {
$tpl->load('box_newlinks', 'box_newlinks_bit');
}
}
// Partner
if ($options['show_partner'] == 1) {
$box_partner = "";
$result = $db->query("SELECT * FROM ".$prefix."partner");
while ($row = $db->fetch_array($result)) {
$tpl->load('box_partner', 'box_partner_bit');
}
}
include './ad.php';
function get_cats($cat_cache, $parent_cat_id = 0, $depth = 0) {
global $children, $tab, $cat, $tpl;
if (is_array($cat_cache)) {
foreach ($cat_cache as $key => $cat) {
if ($cat['parent_cat_id'] == $parent_cat_id) {
$tab = str_repeat('--', $depth);
$tpl->load('cat_list', 'cat_list_bit');
if (isset($children[$cat['cat_id']]) && $children[$cat['cat_id']] == 1) {
get_cats($cat_cache, $cat['cat_id'], $depth + 1);
}
}
}
}
}
function addslashes_array($array) {
foreach ($array as $key => $value) {
$array[$key] = addslashes($value);
}
return $array;
}
// ab hier Update
srand ((double)microtime()*1000000);
if (rand(0,50) == 25) {
$result = $db->query("SELECT cat_id, name, parent_cat_id FROM ".$prefix."cats");
while ($row = $db->fetch_array($result)) {
$cache_cats[$row['cat_id']] = $row;
}
$result = $db->query("SELECT parent_cat_id FROM ".$prefix."links");
while ($row = $db->fetch_array($result)) {
$parent_cat_id = $row['parent_cat_id'];
if (isset($linkcount[$parent_cat_id])) {
$linkcount[$parent_cat_id]++;
} else {
$linkcount[$parent_cat_id] = 1;
}
while ($cache_cats[$parent_cat_id]['parent_cat_id'] != 0) {
// hat parent-cat => inkrementieren
if (isset($linkcount[$cache_cats[$parent_cat_id]['parent_cat_id']])) {
$linkcount[$cache_cats[$parent_cat_id]['parent_cat_id']]++;
} else {
$linkcount[$cache_cats[$parent_cat_id]['parent_cat_id']] = 1;
}
$parent_cat_id = $cache_cats[$parent_cat_id]['parent_cat_id'];
}
}
foreach ($cache_cats as $key => $value) {
if (isset($linkcount[$value['cat_id']])) {
$db->query("UPDATE ".$prefix."cats SET links='".$linkcount[$value['cat_id']]."' WHERE cat_id = '".$value['cat_id']."'");
}
}
}
?>