1

Topic: Question about viewtopic.php

I'm trying to pull a number from another table from within viewtopic.php and display them next to the user's name in each post.

So I insert my code after checking if the user is a member at around line 200:

if ($cur_post['poster_id'] > 1) {

    //
    // show trader feedback
    //
   
    $number_of_ratings=0;   
   
    // get total feedback for user and display it
   
    $result = $db->query('SELECT trade_ref FROM '.$db->prefix.'traderfeedback WHERE id='.$cur_post['poster_id']) or error('Unable to fetch feedback', __FILE__, __LINE__, $db->error());
   
        $number_of_ratings=$db->num_rows($result);
       
        $feedback="Trader Rating (<a href='trader.php?action=view&id=".$cur_post['poster_id']."'>".$number_of_ratings."</a>)";
   
    //
    // end trader feedback
    //

.
.
.

For some reason the db query I inserted seems to end the loop.

Only 1 post is ever displayed, even though there may be many.

Any guidance much appreciated.

Re: Question about viewtopic.php

$result = $db->query('SELECT trade_ref FROM '.$db->prefix.'traderfeedback WHERE id='.$cur_post['poster_id']) or error('Unable to fetch feedback', __FILE__, __LINE__, $db->error());

to

  $resultThatIsntTheSameNameAsThatOtherVarAFewLinesAbove = $db->query('SELECT trade_ref FROM '.$db->prefix.'traderfeedback WHERE id='.$cur_post['poster_id']) or error('Unable to fetch feedback', __FILE__, __LINE__, $db->error());

echo "deadram"; echo; fortune;

3

Re: Question about viewtopic.php

Thanks deadram

I tried that, but it has no effect.

I'm not sure it would have any effect since the $result above mine has finished executing?

Somehow the $db call stops the loop... tearing my hair out!

Re: Question about viewtopic.php

You need to change the main query from unbuffered to buffered (change true to false at the end).

As now, you're replacing the query chace without the current contents being stored elsewhere.

5

Re: Question about viewtopic.php

Thanks elbekko

This would mean I would have to create a new $db function in mysql.php since it looks like the current function is always set to false?

    function query($sql, $unbuffered = false)
    {
        if (defined('PUN_SHOW_QUERIES'))
            $q_start = get_microtime();

        if ($unbuffered)
            $this->query_result = @mysql_unbuffered_query($sql, $this->link_id);
        else
            $this->query_result = @mysql_query($sql, $this->link_id);

        if ($this->query_result)
        {
            if (defined('PUN_SHOW_QUERIES'))
                $this->saved_queries[] = array($sql, sprintf('%.5f', get_microtime() - $q_start));

            ++$this->num_queries;

            return $this->query_result;
        }
        else
        {
            if (defined('PUN_SHOW_QUERIES'))
                $this->saved_queries[] = array($sql, 0);

            return false;
        }

Re: Question about viewtopic.php

Nonono. The false there is just a default value wink

You need to change it in viewtopic.php

7 (edited by idn 2006-09-28 16:42)

Re: Question about viewtopic.php

Thanks. I changed the query in viewtopic.php to:

$r2 = $db->query('SELECT trade_ref FROM '.$db->prefix.'trader WHERE id='.$cur_post['poster_id'], true) or error('Unable to fetch username', __FILE__, __LINE__, $db->error());
    
$number_of_ratings=$db->num_rows($r2);

Same result: only first post is displayed, and instead of num_rows=1, num_rows=0.

:puzzled:

Re: Question about viewtopic.php

You need to change the post fetch query, not your own. Make sure it's buffered.

9

Re: Question about viewtopic.php

elbekko wrote:

You need to change the post fetch query, not your own. Make sure it's buffered.

Thank you very much!

It works perfectly.

Are there any drawbacks to having the main query buffered?

Re: Question about viewtopic.php

It might put some extra load on your server, but you shouldn't notice it...