Seite 3 von 4

Re: Eigene Seite ins Forum integrieren?

Verfasst: 23.02.2012 16:22
von TW1920
ja genau. so meinte ich es. abfragewerte in die variablen und fertig ;)

Code: Alles auswählen

   echo '<tr> 

            <td style="width: 50%" bgcolor="#DBD3B4"><a href="'. $t1 .'" target="_blank" style="text-decoration:none"> 
            <font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:11px" >'. $topic_title .'</a></font>&nbsp;&nbsp;<a href="'. $t1 .'"><img src="../forum/icon_topic_latest.gif" width="11" height="9" alt="Neuester Beitrag" /></a></td> 
            <td style="width: 20%" bgcolor="#DBD3B4"> 
            <font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:11px">'. $last_url .'</font></td> 
            <td style="width: 20%" bgcolor="#DBD3B4"> 
            <font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:11px">'. $last_time .'</font></td> 
         <td style="width: 10%" bgcolor="#DBD3B4"> 
            <font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:11px">'. $last_hour .'</font></td> 


        </tr>'; 
In diesem Teil wird ja die Ausgabe erzeugt. diesen Teil musst du nun in eine Variable geben. Den restlichen HTML_Code der außen drumrum ist fügst du dann außen um die Variable ein ;)

Code: Alles auswählen

<?php
// ############         Edit below         ######################################## 
$topic_length = '60';   // length of topic title 
$topic_limit = '3';   // limit of displayed topics 
$special_forums = '0';   // specify forums ('0' = no; '1' = yes) 
$forum_ids = '3,5,6,7';      // IDs of forums; separate them with a comma 

$config_path = '/';   // path to config.php 
$root_path = 'http://www.vfbfansauerbach.de/portal/';      // link path 
// ############         Edit above         ####################################### 

$path = dirname(__FILE__); 
include_once($path.$config_path .'config.php'); 
mysql_connect($dbhost, $dbuser, $dbpasswd) OR die('Unable to select server.'); 
mysql_select_db($dbname) OR die('Unable to select database.'); 


$where_forums = ( $special_forums == '0' ) ? '' : 't.forum_id NOT IN ('. $forum_ids .') AND '; 
$sql = "SELECT t.*, f.forum_id, f.forum_name, u.username AS first_poster, u.user_id AS first_poster_id, u2.username AS last_poster, u2.user_id AS last_poster_id, p.post_username AS first_poster_name, p2.post_username AS last_poster_name, p2.post_time 
   FROM ". $table_prefix ."topics t, ". $table_prefix ."forums f, ". $table_prefix ."users u, ". $table_prefix ."posts p, ". $table_prefix ."posts p2, ". $table_prefix ."users u2 
   WHERE $where_forums t.topic_poster = u.user_id AND f.forum_id = t.forum_id AND p.post_id = t.topic_first_post_id AND p2.post_id = t.topic_last_post_id AND u2.user_id = p2.poster_id 
   ORDER BY t.topic_last_post_id DESC LIMIT $topic_limit"; 
$result = mysql_query($sql); 
if( !$result ) 
{ 
   die('SQL Statement Error: '. mysql_error()); 
   exit(); 
} 

$line = array(); 
while( $row = mysql_fetch_array($result) ) 
{ 
   $line[] = $row; 
} 

for( $i = 0; $i < count($line); $i++ ) 
{ 
   $forum_id = $line[$i]['forum_id']; 
   $forum_url = $root_path .'viewforum.php?f='. $forum_id; 
   $topic_id = $line[$i]['topic_id']; 
   $topic_url = $root_path .'viewtopic.php?t='. $topic_id; 

   $topic_title = ( strlen($line[$i]['topic_title']) < $topic_length ) ? $line[$i]['topic_title'] : substr(stripslashes($line[$i]['topic_title']), 0, $topic_length) .'...'; 

   $topic_type =  ( $line[$i]['topic_type'] == '2' ) ? 'Announcement ': ''; 
   $topic_type .= ( $line[$i]['topic_type'] == '3' ) ? 'Global Announcement ': ''; 
   $topic_type .= ( $line[$i]['topic_type'] == '1' ) ? 'Sticky ': ''; 
   $topic_type .= ( $line[$i]['topic_vote'] ) ? 'Poll ': ''; 

   $views = $line[$i]['topic_views']; 
   $replies = $line[$i]['topic_replies']; 

   $first_time = date('d.m.Y', $line[$i]['topic_time']); 
   $first_author = ( $line[$i]['first_poster_id'] != '-1' ) ? '<a href="'. $root_path .'profile.php?mode=viewprofile&u='. $line[$i]['first_poster_id'] .'" target="_blank">'. $line[$i]['first_poster'] .'</a>' : ( ($line[$i]['first_poster_name'] != '' ) ? $line[$i]['first_poster_name'] : 'guest' ); 
   $last_time = date('d.m.Y', $line[$i]['post_time']); 
   $last_hour = date('H:i' ,  $line[$i]['post_time']); 
   $last_author = ( $line[$i]['last_poster_id'] != '-1' ) ? $line[$i]['last_poster'] : ( ($line[$i]['last_poster_name'] != '' ) ? $line[$i]['last_poster_name'] : 'guest' ); 
   $t1 = $root_path.'viewtopic.php?f='.$forum_id.'&t='.$topic_id.'&p='.$line[$i]['topic_last_post_id'].'#p'.$line[$i]['topic_last_post_id'];
   $last_url = '<a href="'. $root_path .'viewtopic.php?p='. $line[$i]['topic_last_post_id'] .'#'. $line[$i]['topic_last_post_id'] .'" target="_blank">'. $last_author .'</a>'; 

   // ############## output ############## 
	$template->assign_vars(array(
		'LASTTOPICS'            => sprintf(<tr> 

            <td style="width: 50%" bgcolor="#DBD3B4"><a href="'. $t1 .'" target="_blank" style="text-decoration:none"> 
            <font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:11px" >'. $topic_title .'</a></font>&nbsp;&nbsp;<a href="'. $t1 .'"><img src="../forum/icon_topic_latest.gif" width="11" height="9" alt="Neuester Beitrag" /></a></td> 
            <td style="width: 20%" bgcolor="#DBD3B4"> 
            <font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:11px">'. $last_url .'</font></td> 
            <td style="width: 20%" bgcolor="#DBD3B4"> 
            <font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:11px">'. $last_time .'</font></td> 
         <td style="width: 10%" bgcolor="#DBD3B4"> 
            <font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:11px">'. $last_hour .'</font></td> 


        </tr>),
	));
   // ############## output ############## 
} 

mysql_close(); 
?>


Das wäre dann die neue Datei. über {LASTTOPICS} kannst du dann die Ausgabe abrufen. Vergiss aber nicht den restlichen HTML-Code
vor die Variable:

Code: Alles auswählen

<table border="0" cellpadding="5" cellspacing="2" style="width: 100%" class="table" > 
<body text="#000000" link="#000000" vlink="#000000" alink="#000000"> <body bg="ffffff"> 
   <tr> 
           <td height="30" colspan="4" background="pixelcurrent.gif"><span class="small"><font color="black" face="Verdana, Arial, Helvetica, sans-serif" style="font-size:12px"> 
           &nbsp;&nbsp;Neueste Beiträge im Forum!</font></span></td>
           <br> 
        </tr>
         <tr> 
            <td style="width: 20%" bgcolor="#fcb116"><span class="small"><strong> 
            <font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:11px">Neueste Beiträge</font> 
            </strong> 
            <font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:9px"></font 
            </strong></span></td> 
            <td style="width: 20%" bgcolor="#fcb116"><span class="small"> 
            <strong> 
            <font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:11px">Mitglieder</font> 
            </strong> 
            <font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:9px"></font 
            </strong></span></td> 
            <td style="width: 20%" bgcolor="#fcb116"><span class="small"> 
            <strong> 
            <font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:11px">Datum</font> 
            </strong></span></td> 
         <td style="width: 20%" bgcolor="#fcb116"><span class="small"> 
            <strong> 
            <font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:11px">Uhrzeit</font> 
            </strong></span></td> 


         </tr>
und den nach der Variable

Code: Alles auswählen

</table>
einzufügen. müsste jetzt normal funktionieren ;)


Wenn das so alles passt, fangen wir an, den Code noch etwas zu überarbeiten ;)

Re: Eigene Seite ins Forum integrieren?

Verfasst: 23.02.2012 16:27
von albert0583
Irgendwie bekomme ich keine Verbindung zur Datenbank.

Es kommt diese Fehlermeldung:
[phpBB Debug] PHP Warning: in file [ROOT]/last_topics.php on line 15: mysql_connect() [function.mysql-connect]: Benutzer 'web977'@'localhost' hat keine Zugriffsberechtigung (verwendetes Passwort: Nein)
Unable to select server.
In der last_topics.php ist ja der Pfad zur config.php angegeben also worin liegt der Fehler?

Re: Eigene Seite ins Forum integrieren?

Verfasst: 23.02.2012 16:53
von TW1920
Hab ich befürchtet... Gut, dann passen wir den Code gleich etwas an ;)

zuerst lösche mal die zeile:

Code: Alles auswählen

mysql_close(); 
sag mir obs dann funktioniert hat.

Wir sind ja nun im phpBB-System und können dadurch auch auf funktionen des boardes zurückgreifen. da das board bereits über die common.php, eine db-verfbindung aufbaut, müssen wir das nicht mehr machen. damit wäre nun folgender code aktuell:

Code: Alles auswählen

<?php
// ############         Edit below         ######################################## 
$topic_length = '60';   // length of topic title 
$topic_limit = '3';   // limit of displayed topics 
$special_forums = '0';   // specify forums ('0' = no; '1' = yes) 
$forum_ids = '3,5,6,7';      // IDs of forums; separate them with a comma 

$config_path = '/';   // path to config.php 
$root_path = 'http://www.vfbfansauerbach.de/portal/';      // link path 
// ############         Edit above         ####################################### 

$path = dirname(__FILE__); 

$where_forums = ( $special_forums == '0' ) ? '' : 't.forum_id NOT IN ('. $forum_ids .') AND '; 
$sql = "SELECT t.*, f.forum_id, f.forum_name, u.username AS first_poster, u.user_id AS first_poster_id, u2.username AS last_poster, u2.user_id AS last_poster_id, p.post_username AS first_poster_name, p2.post_username AS last_poster_name, p2.post_time 
   FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2, " . USERS_TABLE . " u2 
   WHERE $where_forums t.topic_poster = u.user_id AND f.forum_id = t.forum_id AND p.post_id = t.topic_first_post_id AND p2.post_id = t.topic_last_post_id AND u2.user_id = p2.poster_id 
   ORDER BY t.topic_last_post_id DESC LIMIT $topic_limit"; 
$result = mysql_query($sql); 
if( !$result ) 
{ 
   die('SQL Statement Error: '. mysql_error()); 
   exit(); 
} 

$line = array(); 
while( $row = mysql_fetch_array($result) ) 
{ 
   $line[] = $row; 
} 

for( $i = 0; $i < count($line); $i++ ) 
{ 
   $forum_id = $line[$i]['forum_id']; 
   $forum_url = $root_path .'viewforum.php?f='. $forum_id; 
   $topic_id = $line[$i]['topic_id']; 
   $topic_url = $root_path .'viewtopic.php?t='. $topic_id; 

   $topic_title = ( strlen($line[$i]['topic_title']) < $topic_length ) ? $line[$i]['topic_title'] : substr(stripslashes($line[$i]['topic_title']), 0, $topic_length) .'...'; 

   $topic_type =  ( $line[$i]['topic_type'] == '2' ) ? 'Announcement ': ''; 
   $topic_type .= ( $line[$i]['topic_type'] == '3' ) ? 'Global Announcement ': ''; 
   $topic_type .= ( $line[$i]['topic_type'] == '1' ) ? 'Sticky ': ''; 
   $topic_type .= ( $line[$i]['topic_vote'] ) ? 'Poll ': ''; 

   $views = $line[$i]['topic_views']; 
   $replies = $line[$i]['topic_replies']; 

   $first_time = date('d.m.Y', $line[$i]['topic_time']); 
   $first_author = ( $line[$i]['first_poster_id'] != '-1' ) ? '<a href="'. $root_path .'profile.php?mode=viewprofile&u='. $line[$i]['first_poster_id'] .'" target="_blank">'. $line[$i]['first_poster'] .'</a>' : ( ($line[$i]['first_poster_name'] != '' ) ? $line[$i]['first_poster_name'] : 'guest' ); 
   $last_time = date('d.m.Y', $line[$i]['post_time']); 
   $last_hour = date('H:i' ,  $line[$i]['post_time']); 
   $last_author = ( $line[$i]['last_poster_id'] != '-1' ) ? $line[$i]['last_poster'] : ( ($line[$i]['last_poster_name'] != '' ) ? $line[$i]['last_poster_name'] : 'guest' ); 
   $t1 = $root_path.'viewtopic.php?f='.$forum_id.'&t='.$topic_id.'&p='.$line[$i]['topic_last_post_id'].'#p'.$line[$i]['topic_last_post_id'];
   $last_url = '<a href="'. $root_path .'viewtopic.php?p='. $line[$i]['topic_last_post_id'] .'#'. $line[$i]['topic_last_post_id'] .'" target="_blank">'. $last_author .'</a>'; 

   // ############## output ############## 
	$template->assign_vars(array(
		'LASTTOPICS'            => sprintf(<tr> 

            <td style="width: 50%" bgcolor="#DBD3B4"><a href="'. $t1 .'" target="_blank" style="text-decoration:none"> 
            <font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:11px" >'. $topic_title .'</a></font>&nbsp;&nbsp;<a href="'. $t1 .'"><img src="../forum/icon_topic_latest.gif" width="11" height="9" alt="Neuester Beitrag" /></a></td> 
            <td style="width: 20%" bgcolor="#DBD3B4"> 
            <font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:11px">'. $last_url .'</font></td> 
            <td style="width: 20%" bgcolor="#DBD3B4"> 
            <font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:11px">'. $last_time .'</font></td> 
         <td style="width: 10%" bgcolor="#DBD3B4"> 
            <font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:11px">'. $last_hour .'</font></td> 


        </tr>),
	));
   // ############## output ############## 
} 


?>
Schau dir auch mal die SQL-Abfrage an, was ich da gemacht hab ;)

Re: Eigene Seite ins Forum integrieren?

Verfasst: 23.02.2012 16:59
von albert0583
Also ich habe jetzt für die Ausgabewerte folgende Variablen erstellt:

Code: Alles auswählen


	'T1'                   => $t1,
	'TOPIC_TITLE'    => $topic_title,
	'LAST_URL'        => $last_url,
	'LAST_TIME'       => $last_time,
	'LAST_HOUR'      => $last_hour,  
diese befinden sich ja in diesem array drin wo schon die anderen Variablen definiert sind.

Nun weiss ich aber nicht wo ich dann diese anderen Teile der last_topics.php definieren soll wie du es beschrieben hast.

Re: Eigene Seite ins Forum integrieren?

Verfasst: 23.02.2012 17:10
von TW1920
Übernimm als erstes mal den code von mir, denn das andere müssen wir dann nochmal um einen schritt mehr überarbeiten, damit auch mehrere beiträge ausgelsen werden können über diese methode ;)

Re: Eigene Seite ins Forum integrieren?

Verfasst: 23.02.2012 17:13
von albert0583
Also die Fehlermeldung kommt immernoch.

Kannst dir ja hier nochmal ansehen

http://www.vfbfansauerbach.de/portal/neueseite.php

Du hast das in der last_topics.php hinzugefügt?

Code: Alles auswählen

$template->assign_vars(array(
      'LASTTOPICS'            => sprintf

Re: Eigene Seite ins Forum integrieren?

Verfasst: 23.02.2012 17:17
von albert0583
TW1920 hat geschrieben:Übernimm als erstes mal den code von mir, denn das andere müssen wir dann nochmal um einen schritt mehr überarbeiten, damit auch mehrere beiträge ausgelsen werden können über diese methode ;)
Sorry aber ich seh nicht mehr durch. Über was schreiben wir jetzt?

Wenn es dir nichts ausmacht dann bitte nochmal von der Stelle als die Verbindung zur DB nicht klappt

Re: Eigene Seite ins Forum integrieren?

Verfasst: 23.02.2012 17:32
von TW1920
Gut, den ersten schritt hast du ja gemacht.

Der zweite wäre die überarbeitete last_topics.php zu verwenden. Dort habe ich dir die sql-abfrage umformuliert, sodass sie die boardeigene verbindung nutzt. Desweiteren habe ich dort auch die tabellen-namen umgeändert, nämlich auf die variablen, die in includes/constants.php definiert sind. damit brauchst du auch nicht immer die variable des db-präfixes angeben ;)

Re: Eigene Seite ins Forum integrieren?

Verfasst: 23.02.2012 17:50
von albert0583
Hab jetzt die last_topics mit deinem Code neu angelegt also mit dem Code von dem Beitrag weiter oben von dir. Nur ist sie doch noch nicht komplett?

Am besten ich lege dir die last_topics.php nochmal ins Pastbin damit du nochmal nachschaust.
LG

Re: Eigene Seite ins Forum integrieren?

Verfasst: 23.02.2012 18:25
von TW1920
Also sie sieht komplett aus. Was sollte fehlen?