MyBB Community Forums

Full Version: Problem whilst using the showthread_linear hook
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm having a very strange problem whilst trying to use the showthread_linear hook to get a list of UID's in a thread. I'm trying to use this hook (rather than the postbit) to try cut down the number of queries I'm using in one of my plugins. Here's my current code:

function myFunction()
{
	global $query, $db; 
	
	$uidList = "uid IN(";
	$comma = "";
	
	while ($uid = $db->fetch_field($query, 'uid')) { 
		$uidList .= "$comma'$uid'";
		
		$comma = ",";
	}
	$uidList .= ")";
}

That should work, right? I should have a perfect string of UIDs. However, printing this out shows absolutely nothing but the following:

uid IN()

Obviously, something's wrong somewhere. I can't for the life of me, figure out what though... Any help would be much appreciated.
An alternative would be to use the postbit hook without a query in combination with showthread_end or showthread_linear to do what you want.

function myPostbitFunction($post)
{
    global $uidlist;

    $uidlist[] = $post['uid'];
}

Then in your other function:

function myFunction()
{
     global $uidlist;

     $uidstring = "uid IN('".implode("','", array_unique($uidlist))."')";
}

That should work if I understand correctly what you want to do.

Edit: Added array_unique() since you wouldn't want the same uid twice.
Ah yes, did not think of doing that, thanks Jammer2x. That should be a more than suitable replacement.
Been thinking on this all day and I've realised my logic is way off and what I was trying to do wouldn't work anyway. Going to have to try a different solution.