1

Topic: Hmm something wrong

I try display last topic subject in last post row in index.php

I change this in function.php

//
// Update posts, topics, last_post, last_post_id and last_poster for a forum (redirect topics are not included)
// If $transaction == PUN_TRANS_END, this function will end the current transaction
//
function update_forum($forum_id, $transaction = 0)
{
    global $db;

    $result = $db->query('SELECT COUNT(id), SUM(num_replies) FROM '.$db->prefix.'topics WHERE moved_to IS NULL AND forum_id='.$forum_id) or error('Unable to fetch forum topic count', __FILE__, __LINE__, $db->error());
    list($num_topics, $num_posts) = $db->fetch_row($result);

    $num_posts = $num_posts + $num_topics;        // $num_posts is only the sum of all replies (we have to add the topic posts)

    $result = $db->query('SELECT last_post, last_post_id, last_poster, subject FROM '.$db->prefix.'topics WHERE forum_id='.$forum_id.' AND moved_to IS NULL ORDER BY last_post DESC LIMIT 1') or error('Unable to fetch last_post/last_post_id/last_poster', __FILE__, __LINE__, $db->error());
    if ($db->num_rows($result))        // There are topics in the forum
    {
        list($last_post, $last_post_id, $last_poster) = $db->fetch_row($result);

        $db->query('UPDATE '.$db->prefix.'forums SET num_topics='.$num_topics.', num_posts='.$num_posts.', last_post='.$last_post.', last_post_id='.$last_post_id.', last_poster=\''.addslashes($last_poster).'\', subject=\''.addslashes($subject).'\' WHERE id='.$forum_id, $transaction) or error('Unable to update last_post/last_post_id/last_poster', __FILE__, __LINE__, $db->error());
    }
    else    // There are no topics
        $db->query('UPDATE '.$db->prefix.'forums SET num_topics=0, num_posts=0, last_post=NULL, last_post_id=NULL, last_poster=NULL, subject=NULL WHERE id='.$forum_id, $transaction) or error('Unable to update last_post/last_post_id/last_poster', __FILE__, __LINE__, $db->error());
}

this in index.php

// Print the categories and forums
$extra_sql = ($cur_user['status'] < PUN_MOD) ? ' WHERE f.admmod_only=\'0\'' : '';

$result = $db->query('SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name, f.forum_desc, f.moderators, f.num_topics, f.num_posts, f.last_post, f.last_post_id, f.last_poster, f.closed, f.subject FROM '.$db->prefix.'categories AS c INNER JOIN '.$db->prefix.'forums AS f ON c.id=f.cat_id'.$extra_sql.' ORDER BY c.disp_position, c.id, f.disp_position') or error('Unable to fetch category/forum list', __FILE__, __LINE__, $db->error());

while ($cur_forum = $db->fetch_assoc($result))
{
    if ($cur_forum['cid'] != $cur_category)    // A new category since last iteration?
    {


AND THIS

// If there is a last_post/last_poster. 
    if ($cur_forum['last_post'] != '')
        $last_post = '<a href="viewtopic.php?pid='.$cur_forum['last_post_id'].'#'.$cur_forum['last_post_id'].'">
<img src="'.$pun_config['o_styleimg_dir'].'/lastpost.gif" alt="ostatni post" border="0" align="middle" ></a> '.format_time($cur_forum['last_post']).'<br><b>'.$lang_common['by'].'</b> '.pun_htmlspecialchars($cur_forum['last_poster']).'</br><b>'.$lang_common['in'].'</b>  <span class="postdetails">'.pun_htmlspecialchars($cur_forum['subject']).'</span>';
    else
        $last_post = '<b>'.$lang_common['by'].'</b></br><b>'.$lang_common['in'].'</b>';

i Add new field subject to forums table in database.
I don't get any error but still i can't display last subject .

Any idea?

2 (edited by Maciek 2004-06-10 22:27)

Re: Hmm something wrong

Hmm i can't test this code but u can try

in functions.php

//
// Update posts, topics, last_post, last_post_id and last_poster for a forum (redirect topics are not included)
// If $transaction == PUN_TRANS_END, this function will end the current transaction
//
function update_forum($forum_id, $transaction = 0)
{
    global $db;

    $result = $db->query('SELECT COUNT(id), SUM(num_replies) FROM '.$db->prefix.'topics WHERE moved_to IS NULL AND forum_id='.$forum_id) or error('Unable to fetch forum topic count', __FILE__, __LINE__, $db->error());
    list($num_topics, $num_posts) = $db->fetch_row($result);

    $num_posts = $num_posts + $num_topics;        // $num_posts is only the sum of all replies (we have to add the topic posts)

    $result = $db->query('SELECT last_post, last_post_id, last_poster, subject FROM '.$db->prefix.'topics WHERE forum_id='.$forum_id.' AND moved_to IS NULL ORDER BY last_post DESC LIMIT 1') or error('Unable to fetch last_post/last_post_id/last_poster', __FILE__, __LINE__, $db->error());
    if ($db->num_rows($result))        // There are topics in the forum
    {
        list($last_post, $last_post_id, $last_poster, $subject) = $db->fetch_row($result);

        $db->query('UPDATE '.$db->prefix.'forums SET num_topics='.$num_topics.', num_posts='.$num_posts.', last_post='.$last_post.', last_post_id='.$last_post_id.', last_poster=\''.addslashes($last_poster).'\', subject=\''.addslashes($subject).'\' WHERE id='.$forum_id, $transaction) or error('Unable to update last_post/last_post_id/last_poster', __FILE__, __LINE__, $db->error());
    }
    else    // There are no topics
        $db->query('UPDATE '.$db->prefix.'forums SET num_topics=0, num_posts=0, last_post=NULL, last_post_id=NULL, last_poster=NULL, subject=NULL WHERE id='.$forum_id, $transaction) or error('Unable to update last_post/last_post_id/last_poster', __FILE__, __LINE__, $db->error());
}

in index.php

// Print the categories and forums
$extra_sql = ($cur_user['status'] < PUN_MOD) ? ' WHERE f.admmod_only=\'0\'' : '';

$result = $db->query('SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name, f.forum_desc, f.moderators, f.num_topics, f.num_posts, f.last_post, f.last_post_id, f.last_poster, f.closed, f.subject FROM '.$db->prefix.'categories AS c INNER JOIN '.$db->prefix.'forums AS f ON c.id=f.cat_id'.$extra_sql.' ORDER BY c.disp_position, c.id, f.disp_position') or error('Unable to fetch category/forum list', __FILE__, __LINE__, $db->error());


AND THIS

// If there is a last_post/last_poster.
    if ($cur_forum['last_post'] != '')
        $last_post = '<a href="viewtopic.php?pid='.$cur_forum['last_post_id'].'#'.$cur_forum['last_post_id'].'">'.format_time($cur_forum['last_post']).'</a><br>'.$lang_common['by'].'  '.pun_htmlspecialchars($cur_forum['last_poster']).'<br>'.$lang_common['in'].' '.pun_htmlspecialchars($cur_forum['subject']);
    else
        $last_post = ' ';

Now u must use something like phpmyadmin and add one field [ subject VARCHAR 255 null ] in forums table . i'm not 100% sure about this but should work's.

The best things in life are free*

* plus shipping and handling

[img]http://members.lycos.co.uk/maciekziolkowski/gmailsign.jpg[/img]

3 (edited by Mac 2004-06-11 13:44)

Re: Hmm something wrong

Hi
Thanks for answer and help .
I test your code right now and i must say it's works but i have one small problem hmm.
When i post new topic i have double subject in viewforum.php sad anyway take a look at screen .

image

4 (edited by Maciek 2004-06-12 11:22)

Re: Hmm something wrong

Mac wrote:

Hi
Thanks for answer and help .
I test your code right now and i must say it's works but i have one small problem hmm.
When i post new topic i have double subject in viewforum.php sad anyway take a look at screen .

image

Hmm i don't have idea right now ,but when i get access to my serwer smile i find bug. Anyway i find your topic about this click and i send email to Simple Exploding Man i give him my code meyby he find solutions fasters if not when i back (1-2 days) to home i find solutions .

The best things in life are free*

* plus shipping and handling

[img]http://members.lycos.co.uk/maciekziolkowski/gmailsign.jpg[/img]

5 (edited by Smartys 2004-06-11 18:10)

Re: Hmm something wrong

I just tried the code and had no problems with it smile

I only had problems when I tried to make it also get the topic id so I could make the subject a link to the topic tongue

Re: Hmm something wrong

Smartys wrote:

I just tried the code and had no problems with it smile

You mean works good .... no double post ,subject and other strange things?
Mac can you send me your post.php on email.

The best things in life are free*

* plus shipping and handling

[img]http://members.lycos.co.uk/maciekziolkowski/gmailsign.jpg[/img]

Re: Hmm something wrong

Nothing strange, everything works exactly how it should, no strange things popping up, etc smile

Thanks btw smile

8

Re: Hmm something wrong

Maciek wrote:
Smartys wrote:

I just tried the code and had no problems with it smile

You mean works good .... no double post ,subject and other strange things?
Mac can you send me your post.php on email.

heh everything works good now smile you are great man

9 (edited by Maciek 2004-06-12 12:06)

Re: Hmm something wrong

Anyway this MOD is not finish yet .
Must add few things :

topic title with more then 20 chars are cut off
mouseover info displays the full title

all info you find here

The best things in life are free*

* plus shipping and handling

[img]http://members.lycos.co.uk/maciekziolkowski/gmailsign.jpg[/img]