Ceva gen Topics Anywhere

Pentru întrebări legate de facilităţile forumului phpBB 2.0.x, acest loc este cel mai potrivit.
Închis
Avatar utilizator
Birkoff
Utilizator înregistrat
Mesaje: 20
Membru din: 11-Ian-2005, 13:04:26
Versiune: 0
Ext: Nu
Server: Windows
Nivel phpBB: Mediu
Localitate: Bucuresti
Contact:

Ceva gen Topics Anywhere

Mesaj de Birkoff »

Salutare

Vreau sa fac un script gen Topics Anywhere dar care sa nu imi returneze un cod java ci direct ultimele 10 mesaje scrise (indiferent de forum). Am reusit sa fac ceva asemanator si a mers o perioada pana am inceput sa sterg unele mesaje din forum si atunci script-ul s-a dat peste cap. Cred ca nu am inteles eu bine logica organizarii bazei de date...

Ma intereseaza daca stie cineva care sunt campurile din bd care ar trebui sa le citesc pentru a afisa ultimele 10 mesaje scrise (indiferent de forum)
Ceva ceva am facut eu, dar daca sterg un mesaj din forum, nu mai corespunde id-ul sau nu stiu ca nu mai merge scriptul pe care l-am facut, imi afiseaza ultimele 10 mesaje dar cu alte link-uri...

Ideea e ca scriptul vreau sa il folosesc pe serverul as.ro unde nu functioneaza Topics Anywhere...

Deci ma poate ajuta cineva sa imi zica care sunt campurile din bd care pastreaza ultimele 10 mesaje scrise?
Avatar utilizator
BuGsY
Fost coleg
Mesaje: 1193
Membru din: 19-Iun-2003, 15:24:49
Ext: Nu
Server: Windows
Nivel phpBB: Mediu
Nivel php: Mediu
Localitate: Constanţa
Contact:

Mesaj de BuGsY »

Cod: Selectaţi tot

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

$config_path = '/forum/';	// path to config.php
$root_path = '/forum/';		// 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.'); 

// ############## output ##############
echo '<table width="100%" cellpadding="1" cellspacing="1" border="0" align="center">
          <tr>
                <th colspan="2">'. $topic_limit .' last topics</th>
          </tr>';
// ############## output ##############

$where_forums = ( $special_forums == '0' ) ? '' : 't.forum_id 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'] .'">'. $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_author = ( $line[$i]['last_poster_id'] != '-1' ) ? $line[$i]['last_poster'] : ( ($line[$i]['last_poster_name'] != '' ) ? $line[$i]['last_poster_name'] : 'guest' );
	$last_url = '<a href="'. $root_path .'viewtopic.php?p='. $line[$i]['topic_last_post_id'] .'#'. $line[$i]['topic_last_post_id'] .'">'. $last_author .'</a>';

	// ############## output ##############
	echo '<tr> 
                        <td valign="top" nowrap="nowrap">'. $topic_type .'<a href="'. $topic_url .'">'. $topic_title .'</a></td>
                    </tr>
                    <tr>
                        <td><a href="'. $forum_url .'">'. $line[$i]['forum_name'] .'</a>: '. $last_url .' '. $last_time .'</td>
                    </tr>';
	// ############## output ##############
}

echo '</table>';
mysql_close();
?>
Avatar utilizator
Birkoff
Utilizator înregistrat
Mesaje: 20
Membru din: 11-Ian-2005, 13:04:26
Versiune: 0
Ext: Nu
Server: Windows
Nivel phpBB: Mediu
Localitate: Bucuresti
Contact:

Mesaj de Birkoff »

Multumesc BuGsY 2 lucruri mai vreau

1. Nu inteleg ce face linia
$path = dirname(__FILE__);

mai exact __FILE__ ca instructiunea dirname stiu ce face...

2. Mi-ar mai trebui si mesajul propriu-zis, nu doar titlul subiectului si linkul, eu facusem sa imi afiseze si mesajul (de fapt x caractere din mesaj), poate imi dai o idee ce mai trebuie sa adaug la interogarea bazei de date... oricum o sa mai studiez codul si poate imi dau singur seama da poate o sa fie mai rapid daca sti tu...
Închis

Înapoi la “2.0.x Cum pot să...?”

Cine este conectat

Utilizatori ce ce navighează pe acest forum: Niciun utilizator înregistrat și 5 vizitatori