Seite 1 von 1

Blätterfunktion in Script einbinden.

Verfasst: 11.04.2005 17:27
von Maffy
Ich erstelle z.Z. eine einfache Linkliste für mein phpBB Forum.

Das Anzeigen der Links klappt soweit auch.

Jetzt möchte ich gerne noch die Blätterfunktion des Forums nutzen.

Welchen Code brauche ich dafür?

Code: Alles auswählen


<?PHP

#######################################
# EZ - WebLink				          #
#######################################

// --> Benötigte Dateien und Variablen von phpBB
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);

// --> Benötigte Dateien und Variablen von WebLink
include($phpbb_root_path . 'link/constants.'.$phpEx);
include($phpbb_root_path . 'link/functions.' . $phpEx );

// --> Welcome Text
$CFG['welcome_text'] = '<b> +++ Weblink Database +++ </b>';

$CFG['text'] = '
<div class="gen" align="center">Dieser Bereich ist noch in Arbeit</div>
';

$CFG['titel_adlink'] = '<b> +++  Link hinzufügen +++ </b>';

// --> Session auslesen und Benutzer-Informationen laden
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);


// --> Link Template laden
$page_title = $lang['Links'];
include($phpbb_root_path . 'includes/page_header.'.$phpEx);

include($phpbb_root_path . 'link/link_header.'.$phpEx);

$template->set_filenames(array(
	'body' => 'links.tpl'));
		
$template->assign_vars(array(
	
	// --> Titel, Text
	'WELCOME_TEXT' => $CFG['welcome_text'] ,
	'TEXT' => $CFG['text'],
	'PAGETITEL'=> $CFG['pagetitel'],
	
	// --> Link Statistik
	'TOTAL_LINKS'=> $totallinks,
	
	// Navigation in der Seite
	'L_LINK_INDEX' => $lang['Link_title'],
	'U_LINK_INDEX' => append_sid('links.'.$phpEx),
	
	'L_LINK_ADD' => $lang['Link_add'],
	'U_LINK_ADD' => append_sid( this_link_url( "mode=add" ) ),	
	
	'L_MOST_POPULAR' => $lang['Link_most_popular'],
	'U_MOST_POPULAR' => append_sid( this_link_url( "mode=stats&stats=popular" ) ),
	
	'L_TOPLINK' => $lang['Link_toplink'],
	'U_LINK_INDEX' => append_sid( this_link_url( "mode=stats&stats=toplink" ) ),
	
	'L_LATEST' => $lang['Link_latest'],
	'U_LATEST' => append_sid( this_link_url( "mode=stats&stats=latest" ) ) 
	
));

$cat_sql = 'SELECT category_id, category_description FROM ' . ezlink_CATEGORY_TABLE . ' ORDER BY category_id ASC';
if(!$cat_result = $db->sql_query($cat_sql)) {
	message_die(GENERAL_ERROR, 'Fehler beim Auslesen der Kategorien-Informationen', '', __LINE__, __FILE__, $cat_sql);
}

while($cat_row = $db->sql_fetchrow($cat_result)) {

	$template->assign_block_vars('category', array(
		'ID' => $cat_row['category_id'],
		'CAT_DESC' => $cat_row['category_description'],
		'U_VIEWCAT' => $cat_row['category_description']		
	));
	
	$link_sql = 'SELECT link_id, link_category_id, link_description, link_url, link_titel
				 FROM ' . ezlink_LINK_TABLE . ' 
				 WHERE link_category_id=' . $cat_row['category_id'] . ' ORDER BY link_id ASC';
	if(!$link_result = $db->sql_query($link_sql)) {
		message_die(GENERAL_ERROR, 'Fehler beim Auslesen der LinkInformationen', '', __LINE__, __FILE__, $forum_sql);
	}

	while($link_row = $db->sql_fetchrow($link_result)) {
	
		$linkurl = $link_row['link_url'];
	
	
		$template->assign_block_vars('category.link', array(
			'ID' => $link_row['link_category_id'],
			'DESC' => $link_row['link_description'],
			'VIEWLINK' => $link_row['link_url'],
			'URL' => $link_row['link_url'],
			'TITEL' => $link_row['link_titel']
		));
	}


}



// --> Seiten entsprechend dem Mode laden
if (isset($_REQUEST["mode"])) {
	$mode = $_REQUEST["mode"];
	}

if (isset($_REQUEST["mode"])) {
	switch ($_REQUEST["mode"]) {

	case "alllink":			include( $link_root_path . 'link/link_all.' . $phpEx );
	case "add":				include( $link_root_path . 'link/link_add.' . $phpEx );
	case "edit":			include( $link_root_path . 'link/link_edit.' . $phpEx );
	case "drop": 			include( $link_root_path . 'link/link_drop.' . $phpEx );
	case "stats": 			include( $link_root_path . 'link/link_stats.' . $phpEx );
	
	default:				print ' Keine Auswahl ';
		
	}
}
	
$template->pparse('body');

include($phpbb_root_path . 'link/link_footer.'.$phpEx);
include($phpbb_root_path . 'includes/page_tail.'.$phpEx);


?>


Verfasst: 11.04.2005 20:19
von QCO
1) Einen Parameter beim Skriptaufruf einführen, der dir sagt, ab welchem Link angezeigt werden soll.
2) Beim SQL-Query, der die Links holt nur eine bestimmte Anzahl holen, beginnend mit Nr. X (siehe 1); d.h. LIMIT verwenden
3) Links einbauen, die auf die einzelnen Seiten verweisen.
Dabei kann dir die Funktion generate_pagination() helfen, die in includes/functions.php liegt und dort auch dokumentiert ist.


Diese Methode ist aber nur sinnvoll, wenn die Reihenfolge deiner Links mit der von dir gewählten Sortierung relativ fest ist, weil sonst der Inhalt der Seiten durcheinander kommt, während ein Nutzer surft.

Verfasst: 12.04.2005 10:53
von Maffy
Ich habe jetzt mal die pagination aus dem Forum eingebaut er zeigt mir jetzt seite 1 von 1 an.

Ich habe allerdings die Anzahl zum testen auf 3 Datensaätze gestellt. Er zeigt mir trotzdem alle Datensätze an.

Was auch noch nicht funktioniert. Wenn kein Datensatz in der Kategorie vorhanden ist, soll er die Kategorie auch nicht anzeigen.

Code: Alles auswählen

<?PHP

#######################################
# EZ - WebLink				          #
#######################################

// --> Benötigte Dateien und Variablen von phpBB
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);

// --> Benötigte Dateien und Variablen von EZ - WebLink
include($phpbb_root_path . 'link/constants.'.$phpEx);
include($phpbb_root_path . 'link/functions.' . $phpEx );

// --> Welcome Text
$CFG['welcome_text'] = '<b> +++ Weblink Database +++ </b>';

$CFG['text'] = '
<div class="gen" align="center">Dieser Bereich ist noch in Arbeit</div>
';

$CFG['titel_adlink'] = '<b> +++  Link hinzufügen +++ </b>';


// --> Blätterfunktion
$start = ( isset($HTTP_GET_VARS['start']) ) ? intval($HTTP_GET_VARS['start']) : 0;

$pagination = '&nbsp;';
$total_links = 3;


// --> Session auslesen und Benutzer-Informationen laden
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);


// --> Link Template laden
$page_title = $lang['Links'];
include($phpbb_root_path . 'includes/page_header.'.$phpEx);

include($phpbb_root_path . 'link/link_header.'.$phpEx);

$template->set_filenames(array(
	'body' => 'links.tpl'));
		
$template->assign_vars(array(
	
	// --> Titel, Text
	'WELCOME_TEXT' => $CFG['welcome_text'] ,
	'TEXT' => $CFG['text'],
	'PAGETITEL'=> $CFG['pagetitel'],
	
	// --> Link Statistik
	'TOTAL_LINKS'=> $totallinks,
	
	// Navigation in der Seite
	'L_LINK_INDEX' => $lang['Link_title'],
	'U_LINK_INDEX' => append_sid('links.'.$phpEx),
	
	'L_LINK_ADD' => $lang['Link_add'],
	'U_LINK_ADD' => append_sid( this_link_url( "mode=add" ) ),	
	
	'L_MOST_POPULAR' => $lang['Link_most_popular'],
	'U_MOST_POPULAR' => append_sid( this_link_url( "mode=stats&stats=popular" ) ),
	
	'L_TOPLINK' => $lang['Link_toplink'],
	'U_LINK_INDEX' => append_sid( this_link_url( "mode=stats&stats=toplink" ) ),
	
	'L_LATEST' => $lang['Link_latest'],
	'U_LATEST' => append_sid( this_link_url( "mode=stats&stats=latest" ) ) 
	
));

$cat_sql = 'SELECT category_id, category_description FROM ' . ezlink_CATEGORY_TABLE . ' ORDER BY category_id ASC';
if(!$cat_result = $db->sql_query($cat_sql)) {
	message_die(GENERAL_ERROR, 'Fehler beim Auslesen der Kategorien-Informationen', '', __LINE__, __FILE__, $cat_sql);
}

while($cat_row = $db->sql_fetchrow($cat_result)) {

	$template->assign_block_vars('category', array(
		'ID' => $cat_row['category_id'],
		'CAT_DESC' => $cat_row['category_description'],
		'U_VIEWCAT' => $cat_row['category_description']		
	));
	
	$link_sql = 'SELECT link_id, link_category_id, link_description, link_url, link_titel
				 FROM ' . ezlink_LINK_TABLE . ' 
				 WHERE link_category_id=' . $cat_row['category_id'] . ' 
				 ORDER BY link_id DESC LIMIT '.$start.', '.$link_config['links_per_page'].' ';
	
	if(!$link_result = $db->sql_query($link_sql)) {
		message_die(GENERAL_ERROR, 'Fehler beim Auslesen der Link Informationen', '', __LINE__, __FILE__, $forum_sql);
	}

	while($link_row = $db->sql_fetchrow($link_result)) {
	
		if($link_row['link_category_id'] == '0'){
		$nodata = " Keine Links in dieser Kategorie vorhanden ";
				
		$template->assign_block_vars('category.link', array(
			'ID' => $link_row['link_category_id'],
			'DESC' => $link_row['link_description'],
			'VIEWLINK' => $link_row['link_url'],
			'URL' => $link_row['link_url'],
			'NODATA' => $nodata,
			'TITEL' => $link_row['link_titel']
			));
		
		}
		
	}


}

// --> Blätterfunktion
	$sql = "SELECT count(*) AS total FROM " . ezlink_LINK_TABLE . " ";

	if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Error getting total links', '', __LINE__, __FILE__, $sql);
	}

	if ( $total = $db->sql_fetchrow($result) )
	{
		$total_links = $total['total'];

		$pagination = generate_pagination("links.$phpEx?mode=$mode&order=$sort_order", $total_links, $link_config['links_per_page'], $start). '&nbsp;';
	}
	$db->sql_freeresult($result);

$template->assign_vars(array(
	'PAGINATION' => $pagination,
	'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / $link_config['links_per_page'] ) + 1 ), ceil( $total_links / $link_config['links_per_page'] )), 

	'L_GOTO_PAGE' => $lang['Goto_page'])
);



// --> Seiten entsprechend dem Mode laden
if (isset($_REQUEST["mode"])) {
	$mode = $_REQUEST["mode"];
	}

if (isset($_REQUEST["mode"])) {
	switch ($_REQUEST["mode"]) {

	case "alllink":			include( $link_root_path . 'link/link_all.' . $phpEx );
	case "add":				include( $link_root_path . 'link/link_add.' . $phpEx );
	case "edit":			include( $link_root_path . 'link/link_edit.' . $phpEx );
	case "drop": 			include( $link_root_path . 'link/link_drop.' . $phpEx );
	case "stats": 			include( $link_root_path . 'link/link_stats.' . $phpEx );
	
	default:				print ' Keine Auswahl ';
		
	}
}
	
$template->pparse('body');

include($phpbb_root_path . 'link/link_footer.'.$phpEx);
include($phpbb_root_path . 'includes/page_tail.'.$phpEx);


?>