Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: PHP Code Help

  1. #1
    New Coder
    Join Date
    Mar 2007
    Posts
    30
    Thanks
    5
    Thanked 0 Times in 0 Posts

    PHP Code Help

    So here is my situation, I have a vBulletin forum which uses PHP documents just like this one does.

    I am trying to alter the poll bar gif width.

    However the problem that I have is that when I change the numeric value that does this, it also changes the numeric value for the % shown as well.

    Before I change the variable it looks like this at 100%



    After I change the variable it looks like this:




    See that.

    How can I make it so that the bar fills up the space, but shows 100% instead of 200%?

    What adjustment to this code do I need to make?

    Code:
    ##################################################################
    ############################### SHOW POLL ######################################
    ################################################################################
    $poll = '';
    if ($thread['pollid'])
    {
    	$pollbits = '';
    	$counter = 1;
    	$pollid = $thread['pollid'];
    
    	$show['editpoll'] = iif(can_moderate($threadinfo['forumid'], 'caneditpoll'), true, false);
    
    	// get poll info
    	$pollinfo = $db->query_first("
    		SELECT *
    		FROM " . TABLE_PREFIX . "poll
    		WHERE pollid = $pollid
    	");
    
    	require_once(DIR . '/includes/class_bbcode.php');
    	$bbcode_parser =& new vB_BbCodeParser($vbulletin, fetch_tag_list());
    
    	$pollinfo['question'] = $bbcode_parser->parse(unhtmlspecialchars($pollinfo['question']), $forum['forumid'], true);
    
    	$splitoptions = explode('|||', $pollinfo['options']);
    	$splitvotes = explode('|||', $pollinfo['votes']);
    
    	$showresults = 0;
    	$uservoted = 0;
    	if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canvote']))
    	{
    		$nopermission = 1;
    	}
    
    	if (!$pollinfo['active'] OR !$thread['open'] OR ($pollinfo['dateline'] + ($pollinfo['timeout'] * 86400) < TIMENOW AND $pollinfo['timeout'] != 0) OR $nopermission)
    	{
    		//thread/poll is closed, ie show results no matter what
    		$showresults = 1;
    	}
    	else
    	{
    		//get userid, check if user already voted
    		$voted = intval(fetch_bbarray_cookie('poll_voted', $pollid));
    		if ($voted)
    		{
    			$uservoted = 1;
    		}
    	}
    
    	($hook = vBulletinHook::fetch_hook('showthread_poll_start')) ? eval($hook) : false;
    
    	if ($pollinfo['timeout'] AND !$showresults)
    	{
    		$pollendtime = vbdate($vbulletin->options['timeformat'], $pollinfo['dateline'] + ($pollinfo['timeout'] * 86400));
    		$pollenddate = vbdate($vbulletin->options['dateformat'], $pollinfo['dateline'] + ($pollinfo['timeout'] * 86400));
    		$show['pollenddate'] = true;
    	}
    	else
    	{
    		$show['pollenddate'] = false;
    	}
    
    	foreach ($splitvotes AS $index => $value)
    	{
    		$pollinfo['numbervotes'] += $value;
    	}
    
    	if ($vbulletin->userinfo['userid'] > 0 AND $pollinfo['numbervotes'] > 0)
    	{
    		$pollvotes = $db->query_read("
    			SELECT voteoption
    			FROM " . TABLE_PREFIX . "pollvote
    			WHERE userid = " . $vbulletin->userinfo['userid'] . " AND pollid = $pollid
    		");
    		if ($db->num_rows($pollvotes) > 0)
    		{
    			$uservoted = 1;
    		}
    	}
    
    	if ($showresults OR $uservoted)
    	{
    		if ($uservoted)
    		{
    			$uservote = array();
    			while ($pollvote = $db->fetch_array($pollvotes))
    			{
    				$uservote["$pollvote[voteoption]"] = 1;
    			}
    		}
    	}
    
    	$option['open'] = $stylevar['left'][0];
    	$option['close'] = $stylevar['right'][0];
    
    	foreach ($splitvotes AS $index => $value)
    	{
    		$arrayindex = $index + 1;
    		$option['uservote'] = iif($uservote["$arrayindex"], true, false);
    		$option['question'] = $bbcode_parser->parse($splitoptions["$index"], $forum['forumid'], true);
    
    		// public link
    		if ($pollinfo['public'] AND $value)
    		{
    			$option['votes'] = '<a href="poll.php?' . $vbulletin->session->vars['sessionurl'] . 'do=showresults&amp;pollid=' . $pollinfo['pollid'] . '">' . $value . '</a>';
    		}
    		else
    		{
    			$option['votes'] = $value;   //get the vote count for the option
    		}
    
    		$option['number'] = $counter;  //number of the option
    
    		//Now we check if the user has voted or not
    		if ($showresults OR $uservoted)
    		{ // user did vote or poll is closed
    
    			if ($value <= 0)
    			{
    				$option['percent'] = 0;
    			}
    			else if ($pollinfo['multiple'])
    			{
    				$option['percent'] = vb_number_format(($value < $pollinfo['voters']) ? $value / $pollinfo['voters'] * 100 : 100, 2);
    			}
    			else
    			{
    				$option['percent'] = vb_number_format(($value < $pollinfo['numbervotes']) ? $value / $pollinfo['numbervotes'] * 100 : 100, 2);
    			}
    
    			$option['graphicnumber'] = $option['number'] % 10 + 1;
    			$option['barnumber'] = round($option['percent']) * 2;
    
    			// Phrase parts below
    			if ($nopermission)
    			{
    				$pollstatus = $vbphrase['you_may_not_vote_on_this_poll'];
    			}
    			else if ($showresults)
    			{
    				$pollstatus = $vbphrase['this_poll_is_closed'];
    			}
    			else if ($uservoted)
    			{
    				$pollstatus = $vbphrase['you_have_already_voted_on_this_poll'];
    			}
    
    			($hook = vBulletinHook::fetch_hook('showthread_polloption')) ? eval($hook) : false;
    
    			eval('$pollbits .= "' . fetch_template('pollresult') . '";');
    		}
    		else
    		{
    			($hook = vBulletinHook::fetch_hook('showthread_polloption')) ? eval($hook) : false;
    
    			if ($pollinfo['multiple'])
    			{
    				eval('$pollbits .= "' . fetch_template('polloption_multiple') . '";');
    			}
    			else
    			{
    				eval('$pollbits .= "' . fetch_template('polloption') . '";');
    			}
    		}
    		$counter++;
    	}
    
    	if ($pollinfo['multiple'])
    	{
    		$pollinfo['numbervotes'] = $pollinfo['voters'];
    		$show['multiple'] = true;
    	}
    
    	if ($pollinfo['public'])
    	{
    		$show['publicwarning'] = true;
    	}
    	else
    	{
    		$show['publicwarning'] = false;
    	}
    
    	$displayed_dateline = $threadinfo['lastpost'];
    
    	($hook = vBulletinHook::fetch_hook('showthread_poll_complete')) ? eval($hook) : false;
    
    	if ($showresults OR $uservoted)
    	{
    		eval('$poll = "' . fetch_template('pollresults_table') . '";');
    	}
    	else
    	{
    		eval('$poll = "' . fetch_template('polloptions_table') . '";');
    	}
    
    }
    I think it precisely has to do with this section of the code, but I don't know how to change it, or what to, to fix this.

    Code:
    $option['barnumber'] = round($option['percent']) * 2;
    Thank you from the bottom of my soul if you can actually help me with this.

    Sincerely,

    Omega

    P.S. Gonna be damn impressed if anyone knows this.

    PPS: I've already asked at vb.org, I've already asked at vb.com, I've been working on this for a week. So now I'm looking to you experts to figure this out if you know how.

  • #2
    New to the CF scene
    Join Date
    Jan 2008
    Posts
    9
    Thanks
    0
    Thanked 1 Time in 1 Post
    well you could try and change the 2 to a 1 and see what happens, didnt trace through the code, but try that first
    m6.net - windows webhosting
    my readlog - what I read

  • #3
    New Coder
    Join Date
    Mar 2007
    Posts
    30
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by skyrider01 View Post
    well you could try and change the 2 to a 1 and see what happens, didnt trace through the code, but try that first
    Thank you bud.

    But the 2 is for the decimal points after 200.00%


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •