1 (edited by Seiteki 2007-06-25 00:39)

Topic: Calling a new MySQL query stops a current one?

I'm currently trying to add a little mod to my forums, but ran into an error.
If I run a new $db->query( 'blah' ); while there is another one currently going on, it stops the old one completely.

I tried searching but didn't find anything, mainly because I'm not sure how to describe this situation.
The function I'm using is this, I just echo it in viewtopic.php

function showRatings( $cur_post )
{
    global $db, $pun_user;
    if ( $pun_user['id'] != $cur_post['poster_id'] )
    {
        $rhtml = '<div class="rate_it"><div class="rate_bar" style="width: 140px;" id="rb_'.$cur_post['id'].'">';
        $rhtml .= '<div class="rate_text" style="width: 140px;" id="rbt_'.$cur_post['id'].'"> </div>';
        $rtres = $db->query( 'SELECT name, image FROM  '.$db->prefix.'ratings' );
        while( $rtrow=mysql_fetch_assoc( $rtres ) )
        {
            $rhtml .= '<div class="rate_button" onmouseover="rateHover(true,\''.$cur_post["id"].'\',\''.$rtrow["name"].'\');" onmouseout="rateHover(false,\''.$cur_post["id"].'\',\'\');"><img src=\''.$rtrow["image"].'\'></div>';
        }
        $rhtml .= '</div></div>';
    }
    return $rhtml;
}

And example is if the function is run, the only post you see is the first post you can rate, otherwise you can see all the posts.

Re: Calling a new MySQL query stops a current one?

This is in viewtopic.php I take it? smile

That's because the main query is set to be unbuffered, so when another query runs after it the resultset gets deleted. You can change this by replacing true with false in the last argument of the main query.

Re: Calling a new MySQL query stops a current one?

elbekko wrote:

This is in viewtopic.php I take it? smile

That's because the main query is set to be unbuffered, so when another query runs after it the resultset gets deleted. You can change this by replacing true with false in the last argument of the main query.

Ah, I see now. I'm more experienced with the default mysql functions and not the punbb versions so I wasn't sure about this.

Re: Calling a new MySQL query stops a current one?

Well, inside the DB layer it translates to either mysql_query() or mysql_unbuffered_query() wink