Show Poll Voters

Mods, snippets and styles postet and supported by the users
Forum rules
As the forum title says this is for User Contributions
Post a support request in this forum and you will be banned!
Locked
Leinad4Mind
BBCoder II
BBCoder II
Posts: 27
Joined: 28 Apr 2011, 12:55

Show Poll Voters

Post by Leinad4Mind »

Show voters under vote bars for Admins and Moderators only

OPEN: viewtopic.php
FIND:

Code: Select all

		$poll_info[$i]['poll_option_text'] = bbcode_nl2br($poll_info[$i]['poll_option_text']);
		$poll_info[$i]['poll_option_text'] = smiley_text($poll_info[$i]['poll_option_text']);
ADD-AFTER:

Code: Select all

		/***********************************************************************************
		Begin 'Show voters' MOD by Ernst Vaarties and edited by Leinad4Mind
		************************************************************************************/
		$sql_voters = '
			SELECT u.username, u.user_colour, pv.vote_user_id
			FROM ' . POLL_VOTES_TABLE . ' pv, ' . USERS_TABLE . ' u
			WHERE pv.topic_id = ' . $topic_id . '
				AND poll_option_id = ' . $poll_info[$i]['poll_option_id'] . '
				AND pv.vote_user_id = u.user_id
			ORDER BY u.username_clean ASC, pv.vote_user_id ASC';

		$results_voters = $db->sql_query($sql_voters);
		$voters_total = 0;
		$voters_string = "";

			// Add all voters to a string.
			while ($row_voters = $db->sql_fetchrow($results_voters))
			{
				$voters_total = $voters_total + 1;
				$voters_string = $voters_string . "<option style='font-weight:bold; color:#" . $row_voters['user_colour'] . "'; value='u=" . $row_voters['vote_user_id'] . "'>" . $row_voters['username'] ."</option>";
				
			}

			// Is the total nr of voters <> the nr of votes for the poll? Add this to the same string.
			if ($voters_total <> $poll_info[$i]['poll_option_total'])
			{
				$voters_string = $voters_string . "<option><> " . ($poll_info[$i]['poll_option_total'] - $voters_total) . "</option>";
			}

		// Add the string to the list.
		$poll_info[$i]['poll_option_voters'] = $voters_string;
		$db->sql_freeresult($results_voters);
		/***********************************************************************************
		Begin 'Show voters' MOD by Ernst Vaarties and edited by Leinad4Mind
		************************************************************************************/


FIND:

Code: Select all

			'POLL_OPTION_VOTED'		=> (in_array($poll_option['poll_option_id'], $cur_voted_id)) ? true : false)

Replace-With:

Code: Select all

			/***********************************************************************************
			Begin 'Show voters' MOD by Ernst Vaarties and edited by Leinad4Mind
			************************************************************************************/
			// 'POLL_OPTION_VOTED'	=> (in_array($poll_option['poll_option_id'], $cur_voted_id)) ? true : false)
			'POLL_OPTION_VOTED'		=> (in_array($poll_option['poll_option_id'], $cur_voted_id)) ? true : false,
			'POLL_OPTION_VOTERS'		=> $poll_option['poll_option_voters'])
			/***********************************************************************************
			Begin 'Show voters' MOD by Ernst Vaarties and edited by Leinad4Mind
			************************************************************************************/


OPEN:
styles/XXXX/template/viewtopic_body.php

FIND In proSilver theme:

Code: Select all

<!-- ELSE -->{poll_option.POLL_OPTION_PERCENT}<!-- ENDIF -->
Replace-With:

Code: Select all

<!-- ELSE --><!-- IF not U_ACP or not U_MCP -->{poll_option.POLL_OPTION_PERCENT}<!-- ENDIF -->
                       <!-- IF U_ACP or U_MCP -->
						<select style="font-size: xx-small;">
							<option>{L_USERNAMES}:</option>";
							<option><span style="font-weight:bold; color:#{S_USER_COLOUR};">{poll_option.POLL_OPTION_VOTERS}</span></option>
                      </select>
                       <!-- ENDIF --><!-- ENDIF -->
8-)

It exists many mods similar. I like this one in this way. Cheers!

Note: This mod is based on evaarties' show poll voters for phpBB3. There are a lot of improvement from the original version. The new features I added are: user colour and cleaning up some codes.
master412160
BBCoder II
BBCoder II
Posts: 39
Joined: 04 Jun 2011, 14:17

Show Poll Voters

Post by master412160 »

I tried it out and it doesn't seem to work that good. It does work without errors but when you select usernames who votes you sometimes get <>1 or a empty value?
Hello please check out my Interview Site, Interviewed You
Leinad4Mind
BBCoder II
BBCoder II
Posts: 27
Joined: 28 Apr 2011, 12:55

Show Poll Voters

Post by Leinad4Mind »

I never face that problem. How can it be reproduced?!
webmaster
BBCoder II
BBCoder II
Posts: 69
Joined: 19 Nov 2011, 23:52
BBCodes: 5
Favourite BBCode: Rainbow
Favourite MOD: Please wait
Location: Bangladesh
Contact:

Show Poll Voters

Post by webmaster »

Thanks bro for yOur new MOD..!!
User avatar
RMcGirr83
BBCoder III
BBCoder III
Posts: 104
Joined: 08 Mar 2010, 13:17
Favourite MOD: mChat
Contact:

Show Poll Voters

Post by RMcGirr83 »

The code you are using will execute a sql query for every answer within a poll. If there are 10 poll answers, then the query will generate 10 times.

This is known as a "query in loop"

Not a very efficient way of doing it, IMHO.
Leinad4Mind
BBCoder II
BBCoder II
Posts: 27
Joined: 28 Apr 2011, 12:55

Show Poll Voters

Post by Leinad4Mind »

Yeah I know, it's always called till the while finish ^^''. But I don't have knowledge to do better. Maybe on the future. If you know how to solve, I am all ears.

Thks
Locked