Forums

Unfortunately no one can be told what FluxBB is - you have to see it for yourself.

You are not logged in.

#1 2010-08-06 03:02:57

HCLivess
Member
Registered: 2010-08-06
Posts: 9

Show categories in forum and topic navigation path - full guide!

Hello, I tried editing viewtopic.php in order to change

" Index » Forum » Topic "
to
" Index » Category » Forum » Topic "

I am a complete noob, but I tried hard and could only get it to the stage of:

" Index » Category number » (nothing at all) "

I tried adding this to viewtopic.php:

line 44: $result = $db->query('SELECT cat_id FROM forums WHERE id='.$id);
line 99: <li>&raquo;&nbsp;<?php echo pun_htmlspecialchars($cur_forum['cat_id']) ?></li>
(on line 99 between the other already present pointers)

Could anyone help me with this please? I would appreciate it very much. I did a few projects in PHP, but I have absolutely no idea how PunBB exactly works even after hours and hours, because the functions seem too intertwined and complicated to me. Thank you!

See for yourself at my site example: http://fet.ezin.cz/viewforum.php?id=18

Last edited by HCLivess (2010-08-06 22:34:53)

Offline

#2 2010-08-06 07:56:04

artoodetoo
Member
From: Far-Far-Away
Registered: 2008-05-11
Posts: 220

Re: Show categories in forum and topic navigation path - full guide!

Of course, $cur_forum['cat_id'] is number. You have to fetch textual field categories.cat_name. Therefore, SELECT will have one more JOIN. Something like this:
INNER JOIN '.$db->prefix.'categories AS c ON c.id=f.cat_id
and then you can use select c.cat_name


I'm not a fan of FluxBB way anymore.

Offline

#3 2010-08-06 08:02:54

Franz
Lead developer
From: Germany
Registered: 2008-05-13
Posts: 6,639
Website

Re: Show categories in forum and topic navigation path - full guide!

FluxBB, not PunBB tongue


fluxbb.de | develoPHP

"As code is more often read than written it's really important to write clean code."

Offline

#4 2010-08-06 11:05:39

HCLivess
Member
Registered: 2010-08-06
Posts: 9

Re: Show categories in forum and topic navigation path - full guide!

Hey Franz, I updated to FluxBB on my test forum and I found out that files that I edited are completely indifferent. As far as 1.2 goes, only the name has been changed, immaright? smile

Offline

#5 2010-08-06 11:08:45

HCLivess
Member
Registered: 2010-08-06
Posts: 9

Re: Show categories in forum and topic navigation path - full guide!

Thanks, R2D2! I wondered very much why "$result = $db->query('SELECT cat_name FROM categories WHERE id='.$id);" did not actually work, its probably because of the fetch thing as you suggested, id never find out myself.

Offline

#6 2010-08-06 11:44:45

Franz
Lead developer
From: Germany
Registered: 2008-05-13
Posts: 6,639
Website

Re: Show categories in forum and topic navigation path - full guide!

You're right.
Just wanted to annoy everybody a little tongue


fluxbb.de | develoPHP

"As code is more often read than written it's really important to write clean code."

Offline

#7 2010-08-06 12:29:06

HCLivess
Member
Registered: 2010-08-06
Posts: 9

Re: Show categories in forum and topic navigation path - full guide!

Alright, I tried this (I edited the JOIN to be totally identical with the JOIN in "forum" table fetching.)

$result = $db->query('SELECT c.cat_name FROM categories AS c LEFT JOIN WHERE c.id='.$id);

echo pun_htmlspecialchars($cur_forum['c.cat_name'])

Not working.
The website now returns a bad request as specified in the "forum" table fetch. Perhaps I cant have the two fetches separately?

EDIT: I think i was a little dumb, now im gonna try actually put it in the original SELECT to be JOINed with the forum

Last edited by HCLivess (2010-08-06 12:51:52)

Offline

#8 2010-08-06 13:11:59

HCLivess
Member
Registered: 2010-08-06
Posts: 9

Re: Show categories in forum and topic navigation path - full guide!

I am helplessly lost. If anyone would like to solve this problem for me, I would appreciate it very much. The original file can be downloaded from here:

http://fet.ezin.cz/filesystem/files/viewforum.download

Thanks in advance for your mercy. The example could help me to understand the code better. Otherwise its time for me to go and study some MySQL from scratch smile

Offline

#9 2010-08-06 16:30:24

HCLivess
Member
Registered: 2010-08-06
Posts: 9

Re: Show categories in forum and topic navigation path - full guide!

--PART 1--

I grew so frustrated that I reprogrammed the whole thing (reedited the code to be the correct one not to confuse anyone, so the replies might point to a removed part of the code):

Create forumfile.php:

change 'server', 'username', 'pass', database'

<?php
//start
//conn
$conn = mysql_connect('server', username', 'pass');
mysql_query("SET CHARACTER SET utf8");
if (!$conn) {
    die('Could not connect: ' . mysql_error());
}
                    ('Error connecting to mysql');
mysql_select_db('database');
//conn
$id_forum = isset($_GET['id']) ? intval($_GET['id']) : 0;

$query = "SELECT cat_id FROM forums WHERE id='$id_forum';";
$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_NUM))
{
    $top2 = "{$row[0]}";
}
//echo $top2;                                                           //show number of category in which the topic is
 
$query  = "SELECT cat_name FROM categories WHERE id= '$top2';";
$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_NUM))
{
    $top3 = "{$row[0]}";
}
//echo $top3;                                                           //show name of category in which the topic is

mysql_close($conn); 
//end
?>

Changes to viewforum.php:

Add this line to viewforum.php:

require PUN_ROOT.'forumfile.php';

Change 2 lines in viewforum.php that start with

<ul><li>

to

<ul><li><a href="index.php"><?php echo $lang_common['Index'] ?></a>&nbsp;</li><li>&raquo;&nbsp;<?php echo $top3;?>&nbsp;</li><li>&raquo;&nbsp;<a href="viewforum.php?id=<?php echo $cur_topic['forum_id'] ?>"><?php echo pun_htmlspecialchars($cur_topic['forum_name']) ?></a></li><li>&nbsp;&raquo;&nbsp;<?php echo pun_htmlspecialchars($cur_topic['subject']) ?></li></ul>

Upload both files directly to thle FluxBB folder.

Last edited by HCLivess (2010-08-08 02:04:46)

Offline

#10 2010-08-06 19:42:05

artoodetoo
Member
From: Far-Far-Away
Registered: 2008-05-11
Posts: 220

Re: Show categories in forum and topic navigation path - full guide!

did not actually work, its probably because of the fetch thing as you suggested, id never find out myself

Ughm. smile Well… It depends on what id you are trying to find smile It is category id, not topic or forum one.

I suggest you to JOIN tables and find category referred by forum (referred by topic)


I'm not a fan of FluxBB way anymore.

Offline

#11 2010-08-06 19:54:19

artoodetoo
Member
From: Far-Far-Away
Registered: 2008-05-11
Posts: 220

Re: Show categories in forum and topic navigation path - full guide!

I have some experience with such trick:
http://punbb-pe.org.ru/viewboard.php?id=7
It is category name instead of silly "Index" in the breadcrumb. And it's done exactly as I sad above.


I'm not a fan of FluxBB way anymore.

Offline

#12 2010-08-06 20:17:15

HCLivess
Member
Registered: 2010-08-06
Posts: 9

Re: Show categories in forum and topic navigation path - full guide!

Sorry man, I confised the whole thing because I was lazy enought to look at the database in detail, my very bad and cost me 2 days, my sleep and you your time. I reedited the code I posted last.

Offline

#13 2010-08-06 22:28:17

HCLivess
Member
Registered: 2010-08-06
Posts: 9

Re: Show categories in forum and topic navigation path - full guide!

--PART 2--

Create topicfile.php:
change 'server', 'username', 'pass', database'

<?php
//start
//conn
$conn = mysql_connect('server', 'username', 'pass');
mysql_query("SET CHARACTER SET utf8");
if (!$conn) {
    die('Could not connect: ' . mysql_error());
}
                    ('Error connecting to mysql');
mysql_select_db('database');
//conn
$id_topic = isset($_GET['tid']) ? intval($_GET['tid']) : 0;
if (empty($id_topic))
{
$id_topic = isset($_GET['id']) ? intval($_GET['id']) : 0;
}

$query = "SELECT forum_id FROM topics WHERE id='$id_topic';";
$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_NUM))
{
    $top1 = "{$row[0]}";
}

echo $top1;                              //number of forum in which the topic is

$query  = "SELECT cat_id FROM forums WHERE id= '$top1';";
$result = mysql_query($query);


while($row = mysql_fetch_array($result, MYSQL_NUM))
{
    $top2 = "{$row[0]}";
}

//echo $top2;                             //number of category in which the forum is

$query  = "SELECT cat_name FROM categories WHERE id= '$top2';";
$result = mysql_query($query);[/b]

while($row = mysql_fetch_array($result, MYSQL_NUM))
{
    $top3 = "{$row[0]}";
}
//echo $top3;                 //name of category in which the forum is

[b]mysql_close($conn); 
//end
?>

Changes to viewtopic.php:
Add this line to viewtopic.php:

require PUN_ROOT.'topicfile.php';

and change 2 lines in viewtopic.php that start with

<ul><li>

to

<ul><li><a href="index.php"><?php echo $lang_common['Index'] ?></a>&nbsp;</li><li>&raquo;&nbsp;<?php echo $top3;?>&nbsp;</li><li>&raquo;&nbsp;<a href="viewforum.php?id=<?php echo $cur_topic['forum_id'] ?>"><?php echo pun_htmlspecialchars($cur_topic['forum_name']) ?></a></li><li>&nbsp;&raquo;&nbsp;<?php echo pun_htmlspecialchars($cur_topic['subject']) ?></li></ul>

Upload both files directly to thle FluxBB folder.

That's all. I know the code might seem unnecesarily bloated, but this way you have an absolute perspective on everything what's going on. Also object access could have been used with some variables, but I have no idea how to quote these outside the file! (when included)

--PART 3--

Create postfile.php:
change 'server', 'username', 'pass', database'

<?php
//start
//conn
$conn = mysql_connect('server', 'username', 'pass');
mysql_query("SET CHARACTER SET utf8");
if (!$conn) {
    die('Could not connect: ' . mysql_error());
}
                    ('Error connecting to mysql');
mysql_select_db('database');
//conn
$id_post = isset($_GET['pid']) ? intval($_GET['pid']) : 0;
if (empty($id_post))
{
$id_post = isset($_GET['id']) ? intval($_GET['id']) : 0;
}

$query = "SELECT topic_id FROM posts WHERE id='$id_post';";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_NUM))
{
    $top0 = "{$row[0]}";
}

//echo $top1;                              //number of forum in which the topic is

$query = "SELECT forum_id FROM topics WHERE id='$top0';";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_NUM))
{
    $top1 = "{$row[0]}";
}

//echo $top1;                              //number of forum in which the topic is

$query  = "SELECT cat_id FROM forums WHERE id= '$top1';";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_NUM))
{
    $top2 = "{$row[0]}";
}

//echo $top2;                             //number of category in which the forum is

$query  = "SELECT cat_name FROM categories WHERE id= '$top2';";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_NUM))
{
    $top3 = "{$row[0]}";
}
//echo $top3;                 //name of category in which the forum is

mysql_close($conn); 
//konec
?>

Add this line to viewtopic.php:

require PUN_ROOT.'postfile.php';

Open edit.php and delete.php and add a new line

require PUN_ROOT.'c_posts.php';

and change the line starting with: 

<ul><li>

to

<ul><li><a href="index.php"><?php echo $lang_common['Index'] ?></a></li><li>&raquo;&nbsp;<?php echo $top3;?>&nbsp;</li><li>&nbsp;&raquo;&nbsp;<a href="viewforum.php?id=<?php echo $cur_post['fid'] ?>"><?php echo pun_htmlspecialchars($cur_post['forum_name']) ?></a></li><li>&nbsp;&raquo;&nbsp;<?php echo pun_htmlspecialchars($cur_post['subject']) ?></li></ul>

Open post.php and add a 2 new lines:

require PUN_ROOT.'forumfile.php';
require PUN_ROOT.'topicfile.php';

Change the line starting with:

<ul><li>

to

<ul><li><a href="index.php"><?php echo $lang_common['Index'] ?></a></li><li>&raquo;&nbsp;<?php echo $top3;?>&nbsp;</li><li>&nbsp;&raquo;&nbsp;<?php echo $forum_name ?><?php if (isset($cur_posting['subject'])) echo '</li><li>&nbsp;&raquo;&nbsp;'.pun_htmlspecialchars($cur_posting['subject']) ?></li></ul>

Careful. Positons of includes are important, because some files simply use ID for either something or something different, e.c. http://fet.ezin.cz/viewtopic.php?pid=415#p415 uses post id, although usually its supposed to use topic id, thats why it first fetches post id (wrong) and then changes it to the topic id (as if at http://fet.ezin.cz/viewtopic.php?id=313)

Last edited by HCLivess (2010-08-08 10:22:19)

Offline

#14 2010-08-06 22:58:17

Franz
Lead developer
From: Germany
Registered: 2008-05-13
Posts: 6,639
Website

Re: Show categories in forum and topic navigation path - full guide!

Try replacing this query in the viewtopic.php code you posted:

// Fetch some info about the forum
$result = $db->query('SELECT f.forum_name, f.redirect_url, f.moderators, f.num_topics, f.sort_by, fp.post_topics FROM '.$db->prefix.'forums AS f LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND f.id='.$id) or error('Unable to fetch forum info', __FILE__, __LINE__, $db->error());

With this code:

// Fetch some info about the forum
$result = $db->query('SELECT f.forum_name, f.redirect_url, f.moderators, f.num_topics, f.sort_by, fp.post_topics, c.id AS cat_id, c.cat_name FROM '.$db->prefix.'forums AS f INNER JOIN '.$db->prefix.'categories AS c ON c.id=f.cat_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND f.id='.$id) or error('Unable to fetch forum info', __FILE__, __LINE__, $db->error());

You can now access the category ID and name with the following two variables

$category_id = $cur_forum['cat_id'];
$category_name = $cur_forum['cat_name'];

fluxbb.de | develoPHP

"As code is more often read than written it's really important to write clean code."

Offline

#15 2010-08-06 23:12:55

HCLivess
Member
Registered: 2010-08-06
Posts: 9

Re: Show categories in forum and topic navigation path - full guide!

Thanks! JOINs are said to be the most difficult operations in SQL and they seem a little confusing to me. I first tried to add something like you suggested to the line you posted, but I only guessed what could that be and went repeatedly wrong smile I'll try those tomorrow perhaps.

Last edited by HCLivess (2010-08-06 23:16:58)

Offline

Board footer

Powered by FluxBB