MyBB Community Forums

Full Version: Portal Recent Threads - If thread contains a poll, show whether user has voted
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
When I use that code I get this error;

Quote:Parse error: syntax error, unexpected '.' in /home/nintend4/public_html/nlpolls.php on line 45

Sorry for being a pain. I bet you wish you never opened this thread Toungue
$votes = 'This poll has '.my_number_format($polls[(int)$poll['pid']]).' votes.'.

is missing a ;
Think its supposed to be:

$votes = 'This poll has '.my_number_format($polls[(int)$poll['pid']]).' votes.';
(2012-09-24, 01:05 AM)anori Wrote: [ -> ]
$votes = 'This poll has '.my_number_format($polls[(int)$poll['pid']]).' votes.'.

is missing a ;
Think its supposed to be:

$votes = 'This poll has '.my_number_format($polls[(int)$poll['pid']]).' votes.';

Thanks. I changed that but the parse error above still appears Sad
My bad, fixed in my last post Smile

Note that you should add this:
    $votes = 'This poll has '.my_number_format($polls[(int)$poll['pid']]).' votes.';
    $mark = '';
    if(isset($votes[(int)$thread['poll']]))
    {
        $mark = '<span title="You already voted for this poll.">*</span>';
    }

Inside your while loop.
Thanks again, but it still gives me the same error. I'm guessing I screwed something up somewhere else in the php file causing the problem. If you maybe wouldn't mind checking, here is the whole php file with your latest code added;

<?php 

define('IN_MYBB', 1); require "./global.php";

add_breadcrumb("Polls", "nlpolls.php"); 

// get forums user cannot view
$unviewable = get_unviewable_forums(true);
if($unviewable)
{
        $unviewwhere = " AND fid NOT IN ($unviewable)";
}

        $altbg = alt_trow();
        $threadlist = '';
$query = $db->query("
                SELECT t.*, u.username, u.displaygroup, u.avatar, u.usergroup, u.avatardimensions, f.name AS forumname, lp.avatar as lpavatar, t.username AS threadusername
                FROM ".TABLE_PREFIX."threads t
                LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=t.uid)
                LEFT JOIN ".TABLE_PREFIX."users lp ON (lp.uid=t.lastposteruid)
                LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid=t.fid)    
                WHERE 1=1 $unviewwhere AND t.visible='1' AND t.closed NOT LIKE 'moved|%' AND t.poll > 0 
                ORDER BY t.lastpost DESC
                LIMIT 0, 10"
        );
$pids = $polls = $votes = array();
while($pid = $db->fetch_field($query, 'poll'))
{
    $pids[] = (int)$pid;
}

$query_p = $db->simple_select('polls', 'pid, numvotes', "pid IN ('".implode("','", $pids)."')");
while($poll = $db->fetch_array($query_p))
{
    $polls[(int)$poll['pid']] = (int)$poll['numvotes'];
}

$query_p = $db->simple_select('pollvotes', 'pid', "pid IN ('".implode("','", $pids)."') AND uid='{$mybb->user['uid']}'");
while($vote = $db->fetch_field($query_p, 'pid'))
{
    $votes[(int)$vote['pid']] = 1;
}

// this is your while loop
while($thread = ...)
{
    $votes = 'This poll has '.my_number_format($polls[(int)$poll['pid']]).' votes.';
    $mark = '';
    if(isset($votes[(int)$thread['poll']]))
    {
        $mark = '<span title="You already voted for this poll.">*</span>';
    }
} 	

                $lastpostdate = my_date($mybb->settings['dateformat'], $thread['lastpost']);
                $lastposttime = my_date($mybb->settings['timeformat'], $thread['lastpost']);
                // Don't link to guest's profiles (they have no profile).
                if($thread['lastposteruid'] == 0)
                {
                        $lastposterlink = $thread['lastposter'];
                }
                else
                {
                        $lastposterlink = build_profile_link($thread['lastposter'], $thread['lastposteruid']);
                }
				        if($thread['lpavatar'])
        {
        $thread['lpavatar'] = htmlspecialchars_uni($thread['lpavatar']);
        }
        else
        {
        $thread['lpavatar'] = $mybb->settings['bburl']."/images/default_avatar.gif"; $thread['avatardimensions'] = "45|45";
        }
        if($thread['avatar'])
        {
        $thread['avatar'] = htmlspecialchars_uni($thread['avatar']);
        }
        else
        {
        $thread['avatar'] = $mybb->settings['bburl']."/images/default_avatar.gif"; $thread['avatardimensions'] = "45|45";
        }
		
                if(my_strlen($thread['subject']) > 100)
                {
                        $thread['subject'] = my_substr($thread['subject'], 0, 100) . "...";
                }
                $thread['subject'] = htmlspecialchars_uni($thread['subject']);
                $thread['threadlink'] = get_thread_link($thread['tid']);
                $thread['lastpostlink'] = get_thread_link($thread['tid'], 0, "lastpost");
				$thread['username'] = $thread['threadusername'];
				$threadstarter = build_profile_link($thread['username'], $thread['uid']);
				$thread['profilelink'] = $thread['threadusername'];	
				eval("\$threadlist .= \"".$templates->get("portal_latestpolls_poll")."\";");
                $altbg = alt_trow();
				
				
        }
        if($threadlist)
        {
                // Show the table only if there are threads
                eval("\$nlpolls = \"".$templates->get("portal_latestpolls")."\";");
        } 
		
	
	
eval("\$html = \"".$templates->get("nintendolounge_polls")."\";"); 

output_page($html);

?>
^_^u

while($thread = ...)

Should be:
while($thread = $db->fetch_array($query))

Try this whole new file:
<?php 

define('IN_MYBB', 1); require "./global.php";

add_breadcrumb("Polls", "nlpolls.php"); 

// get forums user cannot view
$unviewable = get_unviewable_forums(true);
if($unviewable)
{
        $unviewwhere = " AND fid NOT IN ($unviewable)";
}

        $altbg = alt_trow();
        $threadlist = '';
$query = $db->query("
                SELECT t.*, u.username, u.displaygroup, u.avatar, u.usergroup, u.avatardimensions, f.name AS forumname, lp.avatar as lpavatar, t.username AS threadusername
                FROM ".TABLE_PREFIX."threads t
                LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=t.uid)
                LEFT JOIN ".TABLE_PREFIX."users lp ON (lp.uid=t.lastposteruid)
                LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid=t.fid)    
                WHERE 1=1 $unviewwhere AND t.visible='1' AND t.closed NOT LIKE 'moved|%' AND t.poll > 0 
                ORDER BY t.lastpost DESC
                LIMIT 0, 10"
        );
$pids = $polls = $votes = array();
while($pid = $db->fetch_field($query, 'poll'))
{
    $pids[] = (int)$pid;
}

$query_p = $db->simple_select('polls', 'pid, numvotes', "pid IN ('".implode("','", $pids)."')");
while($poll = $db->fetch_array($query_p))
{
    $polls[(int)$poll['pid']] = (int)$poll['numvotes'];
}

$query_p = $db->simple_select('pollvotes', 'pid', "pid IN ('".implode("','", $pids)."') AND uid='{$mybb->user['uid']}'");
while($vote = $db->fetch_field($query_p, 'pid'))
{
    $votes[(int)$vote['pid']] = 1;
}

// this is your while loop
while($thread = $db->fetch_array($query))
{
    $votes = 'This poll has '.my_number_format($polls[(int)$poll['pid']]).' votes.';
    $mark = '';
    if(isset($votes[(int)$thread['poll']]))
    {
        $mark = '<span title="You already voted for this poll.">*</span>';
    }

                $lastpostdate = my_date($mybb->settings['dateformat'], $thread['lastpost']);
                $lastposttime = my_date($mybb->settings['timeformat'], $thread['lastpost']);
                // Don't link to guest's profiles (they have no profile).
                if($thread['lastposteruid'] == 0)
                {
                        $lastposterlink = $thread['lastposter'];
                }
                else
                {
                        $lastposterlink = build_profile_link($thread['lastposter'], $thread['lastposteruid']);
                }
                        if($thread['lpavatar'])
        {
        $thread['lpavatar'] = htmlspecialchars_uni($thread['lpavatar']);
        }
        else
        {
        $thread['lpavatar'] = $mybb->settings['bburl']."/images/default_avatar.gif"; $thread['avatardimensions'] = "45|45";
        }
        if($thread['avatar'])
        {
        $thread['avatar'] = htmlspecialchars_uni($thread['avatar']);
        }
        else
        {
        $thread['avatar'] = $mybb->settings['bburl']."/images/default_avatar.gif"; $thread['avatardimensions'] = "45|45";
        }
        
                if(my_strlen($thread['subject']) > 100)
                {
                        $thread['subject'] = my_substr($thread['subject'], 0, 100) . "...";
                }
                $thread['subject'] = htmlspecialchars_uni($thread['subject']);
                $thread['threadlink'] = get_thread_link($thread['tid']);
                $thread['lastpostlink'] = get_thread_link($thread['tid'], 0, "lastpost");
                $thread['username'] = $thread['threadusername'];
                $threadstarter = build_profile_link($thread['username'], $thread['uid']);
                $thread['profilelink'] = $thread['threadusername'];    
                eval("\$threadlist .= \"".$templates->get("portal_latestpolls_poll")."\";");
                $altbg = alt_trow();
                
                
}
$nlpoll = '';
if($threadlist)
{
		// Show the table only if there are threads
		eval("\$nlpolls = \"".$templates->get("portal_latestpolls")."\";");
} 
        
    
    
eval("\$html = \"".$templates->get("nintendolounge_polls")."\";"); 

output_page($html);

?>
Its not your mistake yoshi.

This line:


// this is your while loop
while($thread = ...)

Should be i think:

// this is your while loop
while($thread = "...")

Could be completely wrong though. But i think those ... are some string so.

Nevermind Big Grin
Well that error has gone, but I now get a different one Toungue

Quote:Parse error: syntax error, unexpected '}' in /home/nintend4/public_html/nlpolls.php on line 102

I tried deleting that '}' on line 102 but then no threads appear.

I think something has put a curse on that file Toungue
Try the code in my last post, you copied/pasted the code on a wrong way ^_^u
Oops Toungue

Ok I copied and pasted the latest code again and now that error has gone, but now no threads appear at all (link here btw).
Pages: 1 2 3