Topic: Getting the Forum Name from its ID number?

I'm trying to Modify a MOD I installed last night.

Active Topics: http://punbb.org/forums/viewtopic.php?id=4160

I'd post this there, but that thread seems really dead and I'm sure this question could be answered here too.

It seems the MOD as it is has no way of retrieving the name of the forum a topic is attached to. It does have the ID number of course. So as it is, I am able to display the ID number of the forum the active topics are attached to. But I want to take that number and convert it into its equivalent real name. I hope that was clear. Obviously I'm going to have to add some code to read the database. But I don't know enough about getting table names and stuff to know where to start in that regard.

Here is the code I have as it is. It's highly modified from what is available in that thread.

<?php

$active_topic_limit = 10; // change this to the number of active topics you want to display.
$result = $db->query('SELECT t.* FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_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 t.moved_to IS NULL ORDER BY t.last_post DESC    LIMIT '.$active_topic_limit) or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());

require PUN_ROOT.'lang/'.$pun_user['language'].'/forum.php';

?>
<div id="vf" class="blocktable">
    <h2><span>Active Topics</span></h2>
    <div class="box">
        <div class="inbox">
            <table cellspacing="0">
            <thead>
                <tr>
                    <th class="tcl" scope="col"><?php echo $lang_common['Topic'] ?></th>
                    <th class="tc2" scope="col"><?php echo $lang_common['Replies'] ?></th>
                    <th class="tc3" scope="col"><?php echo $lang_forum['Views'] ?></th>
                    <th class="tcr" scope="col"><?php echo $lang_common['Last post'] ?></th>
                </tr>
            </thead>
            <tbody>
<?php
// If there are topics in this forum.
if ($db->num_rows($result))
{
    while ($cur_topic = $db->fetch_assoc($result))
    {
        $item_status = '';

        if ($pun_config['o_censoring'] == '1')
            $cur_topic['subject'] = censor_words($cur_topic['subject']);

        $last_post = '<a href="viewtopic.php?pid='.$cur_topic['last_post_id'].'#p'.$cur_topic['last_post_id'].'">'.pun_htmlspecialchars($cur_topic['subject']).'</a>';

        if (!$pun_user['is_guest'] && $cur_topic['last_post'] > $pun_user['last_visit'])
        {
            $item_status .= ' inew';
            $last_post = '<strong>'.$last_post.'</strong>';
        }

        if ($cur_topic['sticky'] == '1')
        {
            $last_post = '<span class="stickytext">'.$lang_forum['Sticky'].': </span>'.$last_post;
            $item_status .= ' isticky';
        }
?>
                 <tr<?php if ($item_status != '') echo ' class="'.$item_status.'"'; ?>>
                    <td class="tcl">
                        <div class="intd">
                            <!--<div class="<?php echo $icon_type ?>"><div class="nosize"><?php echo $icon_text ?></div></div>//-->
                            <div class="tclcon">
                                <?php echo $last_post.' in '.pun_htmlspecialchars($cur_topic['forum_id']); ?>
                            </div>
                        </div>
                    </td>
                    <td class="tc2"><?php echo $cur_topic['num_replies']; ?></td>
                    <td class="tc3"><?php echo $cur_topic['num_views']; ?></td>
                    <td class="tcr"><?php echo format_time($cur_topic['last_post']); ?> by <?php echo pun_htmlspecialchars($cur_topic['last_poster']); ?></td>
                </tr>
                               
<?php
    }
}
else
{
?>
                <tr>
                    <td class="tcl" colspan="4"><?php echo '*EMPTY*' ?></td>
                </tr>
<?php

}
?>
            </tbody>
            </table>
        </div>
    </div>
</div>

And here is my Forum. The Active Topic table is at the bottom of the page.
http://www.jasoco.net/geekpub/index.php
Note the numbers next to the topic names. I want to take those numbers and turn them into their forum names.

The line <?php echo $last_post.' in '.pun_htmlspecialchars($cur_topic['forum_id']); ?> is the problem. I want to take $cur_topic['forum_id'] and wrap it in another array that returns the forum name.

Thanks for any help. smile

Re: Getting the Forum Name from its ID number?

Try just adding the forum name to the select query. E.g:

SELECT t.*, f.forum_name FROM ...

You can then grab the forum name from $cur_topic['forum_name'].

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: Getting the Forum Name from its ID number?

That worked! Thanks! I'm still learning all the MySQL access stuff so pardon my ignorance.