Seite 1 von 2

Abfrage der Gesamtanzahl von Knowledgebase-Artikel

Verfasst: 23.06.2006 13:13
von Maidenaustria
Hallo!

Ich hab diese Frage schon im Modding-Forum gepostet, jedoch komm ich da nicht weiter!

Ich will, ähnlich der Anzeige der Anzahl aller Postings, eine Anzeige der Anzahl aller Artikel in der Knowledgebase machen.

Kann mir da jemand helfen?
Bitte - Danke!

Verfasst: 23.06.2006 16:15
von Maxxxx
Probiere es doch mit folgendem SQL-Befehl

Code: Alles auswählen

SELECT COUNT(*) FROM deine_tabelle
Ob dieser Befehl für die praktikabel ist, kann ich dir allerdings nicht sagen.

Verfasst: 23.06.2006 16:28
von bazillus
hm, schau dir mal in der functions.php
die funktion

Code: Alles auswählen

function get_db_stat($mode)
an und dazu in der index.php folgende Zeile

Code: Alles auswählen

$total_posts = get_db_stat('postcount');
dabei natürlich den weiteren Weg der Variable in der index.php verfolgen und das dann für die kb nachmachen...

Verfasst: 01.07.2006 20:43
von Maidenaustria
SORRY DAS ICH SO SPÄT ANTWORTE!
Vorest einmal vielen Dank für eure Tipps und etwas zum weiteren Verständniss.
Ich bin ein Absoluter php-Anfänger, also wenn in den folgenden Zeilen der Ultra-Schwachsinn zu lesen ist - bitte nicht steinigen!

Ich hab mir das in der Art so rausgepickt:

In die functions.php ab Zeile 73:

Code: Alles auswählen

function get_db_stat($mode)
{
	global $db;

	switch( $mode )
	{
		case 'countarticles':
			$sql = "SELECT COUNT(article_id) AS total
				FROM " . KB_ARTICLES_TABLE . "
				WHERE article <> " . ANONYMOUS;
			break;

	}

	if ( !($result = $db->sql_query($sql)) )
	{
		return false;
	}

	$row = $db->sql_fetchrow($result);

	switch ( $mode )
	{
		case 'countarticles':
			return $row['total'];
			break;
	}

	return false;
}

In die index.php ab Zeile 280:

Code: Alles auswählen

$total_kbarticles = get_db_stat('countarticles');
und gleich darunter:

Code: Alles auswählen

if( $total_kbarticles == 0 )
{
	$l_total_kbarticles_s = $lang['Kbarticles_zero_total'];
}
else if( $total_kbarticles == 1 )
{
	$l_total_kbarticles_s = $lang['Kbarticles_total'];
}
else
{
	$l_total_kbarticles_s = $lang['Kbarticle_total'];
}

und in Zeile 649:

Code: Alles auswählen

'TOTAL_KBArticles' => sprintf($l_total_kbarticles_s, $total_kbarticles),

und in der lang_main.php:

Code: Alles auswählen

$lang['Kbarticles_zero_total'] = 'Our KB has <b>0</b> articles'; // Number of posts
$lang['Kbarticles_total'] = 'Our KB has <b>%d</b> articles'; // Number of posts
$lang['Kbarticle_total'] = 'Our KB has <b>%d</b> article'; // Number of posts
Dann nur noch {TOTAL_KBArticles} in die index_body.tpl einfügen!

Kann mir jemand sagen ob ich da annähnernd etwas dabei herausbekomme???

PS: Das ANONYNOUS kommt mir noch etwas seltsam vor...

Verfasst: 02.07.2006 15:34
von bazillus
Sieht schon ganz gut aus, hab zwar auch nicht die Ahnung, aber ich würde es so lösen

FIND /includes/functions.php

Code: Alles auswählen

	case 'usercount':
			$sql = "SELECT COUNT(user_id) AS total
				FROM " . USERS_TABLE . "
				WHERE user_id <> " . ANONYMOUS;
			break;
AFTER, ADD

Code: Alles auswählen

case 'countarticles':
         $sql = "SELECT COUNT(article_id) AS total
            FROM " . KB_ARTICLES_TABLE;
         break; 

Also wie bei dir, aber ohne "where" - keine Ahnung wofür Du das brauchst ;)

FIND

Code: Alles auswählen

case 'usercount':
			return $row['total'];
			break;
AFTER, ADD

Code: Alles auswählen

case 'countarticles':
         return $row['total'];
         break; 
der Rest sollte so funktionieren, teste es einfach mal :)

Verfasst: 02.07.2006 16:04
von Maidenaustria
bazillus hat geschrieben:Also wie bei dir, aber ohne "where" - keine Ahnung wofür Du das brauchst ;)
Hab ja auch keine Ahnung - so weit kenn ich mich nicht aus (Hab Euch aber gewarnt :P )

Egal, ich werde es testen und geb Euch Bescheid!
Vielen Dank einstweilen und bis später!

Verfasst: 02.07.2006 22:08
von Maidenaustria
Sieht gut aus - ich hab zumindest keine Fehler!

Nur bei der Abfrage an die DB dürfte noch was faul sein....

Bei der Abfrage dürfte nix herauskommen, denn von:

Code: Alles auswählen

if( $total_kbarticles == 0 ) 
{ 
   $l_total_kbarticles_s = $lang['Kbarticles_zero_total']; 
} 
else if( $total_kbarticles == 1 ) 
{ 
   $l_total_kbarticles_s = $lang['Kbarticles_total']; 
} 
else 
{ 
   $l_total_kbarticles_s = $lang['Kbarticle_total']; 
} 

Bekomme ich immer die Variable

Code: Alles auswählen

$lang['Kbarticles_zero_total']
als Ausgabe...

Also faktisch:

Code: Alles auswählen

$lang['Kbarticles_zero_total'] = 'Die Enzyklopädie beinhaltet <b>0</b> Releases'; // Number of posts


obwohl ~500 Artikel online sind...

Verfasst: 02.07.2006 22:41
von Maidenaustria
Kann es sein das es nicht funktioniert weil meine Article ID erst bei 5 beginnt???

Muss die Tabelle durchgehend sein?

Verfasst: 02.07.2006 22:56
von bazillus
Die Definierung der KB-Tabellen (KB_ARTICLES_TABLE) findet nicht, wie sonst üblich in der constants.php statt, sondern irgendwo anders!

quick&dirty

öffne includes/constants.php

FIND

Code: Alles auswählen

define('VOTE_USERS_TABLE', $table_prefix.'vote_voters');
AFTER, ADD

Code: Alles auswählen

define('KB_ARTICLES_TABLE', $table_prefix.'kb_articles');
Ich weiß nicht, ob das die KB irgendwie stört, viel Spass beim testen ;)!

Verfasst: 02.07.2006 23:09
von fanrpg
Maidenaustria hat geschrieben:Kann es sein das es nicht funktioniert weil meine Article ID erst bei 5 beginnt???

Muss die Tabelle durchgehend sein?
Nein.

suche:

mal ein ganz neuer Ansatz...

öffne: includes/functions.php

suche:

Code: Alles auswählen

		case 'usercount':
			$sql = "SELECT COUNT(user_id) AS total
				FROM " . USERS_TABLE . "
				WHERE user_id <> " . ANONYMOUS;
			break;
dannach einfügen:

Code: Alles auswählen

		case 'totalkb':
			$sql = "SELECT article_id 
				FROM " . KB_ARTICLES_TABLE;
			break;	
suche:

Code: Alles auswählen

$row = $db->sql_fetchrow($result);
ersetze mit:

Code: Alles auswählen

	if( $mode == 'totalkb' )
	{
		$total = $db->sql_numrows($result);
	}
	else
	{
		$row = $db->sql_fetchrow($result);
	}
suche:

Code: Alles auswählen

		case 'topiccount':
			return $row['topic_total'];
			break;
dannach einfügen:

Code: Alles auswählen

		case 'totalkb':
			return intval($total);
			break;
und in der index.php
statt:

Code: Alles auswählen

$total_kbarticles = get_db_stat('countarticles');
das, benutzen:

Code: Alles auswählen

$total_kbarticles = get_db_stat('totalkb');
und anstatt:

Code: Alles auswählen

if( $total_kbarticles == 0 ) 
{ 
   $l_total_kbarticles_s = $lang['Kbarticles_zero_total']; 
} 
else if( $total_kbarticles == 1 ) 
{ 
   $l_total_kbarticles_s = $lang['Kbarticles_total']; 
} 
else 
{ 
   $l_total_kbarticles_s = $lang['Kbarticle_total']; 
}
das benutzen:

Code: Alles auswählen

if( $total_kbarticles == 1 ) 
{ 
   $l_total_kbarticles_s = $lang['Kbarticle_total']; 
} 
else if( $total_kbarticles > 1 ) 
{ 
   $l_total_kbarticles_s = sprintf($lang['Kbarticles_total'], $total_kbarticles);
} 
else 
{ 
   $l_total_kbarticles_s = $lang['Kbarticles_zero_total'];
}
und ansatt das:

Code: Alles auswählen

'TOTAL_KBArticles' => sprintf($l_total_kbarticles_s, $total_kbarticles),
einfach das:

Code: Alles auswählen

'TOTAL_KBArticles' => $l_total_kbarticles_s,
und in den lang Variabeln einfach so benutzen:

Code: Alles auswählen

$lang['Kbarticles_zero_total'] = 'Our KB has <b>0</b> articles'; // Number of posts 
$lang['Kbarticles_total'] = 'Our KB has <b>%s</b> articles'; // Number of posts 
$lang['Kbarticle_total'] = 'Our KB has <b>one</b> article'; // Number of posts
Das dürfte dann funktionieren :)