Page 1 of 1

Vote for president!

Posted: 02 Oct 2012, 05:10
by Solidjeuh
This is the 'Vote for president' snippet.
This is not mine! I grabbed part of the code from the Board3 portal random member module.

------------------------------------------

open index.php

Find:

Code: Select all

// Assign index specific vars
Add before:

Code: Select all

		switch ($db->sql_layer)
		{
			case 'postgres':
			$sql = 'SELECT *
				FROM ' . USERS_TABLE . '
				WHERE user_type <> ' . USER_IGNORE . '
				AND user_type <> ' . USER_INACTIVE . '
				ORDER BY RANDOM()';
			break;

			case 'mssql':
			case 'mssql_odbc':
			$sql = 'SELECT *
				FROM ' . USERS_TABLE . '
				WHERE user_type <> ' . USER_IGNORE . '
				AND user_type <> ' . USER_INACTIVE . '
				ORDER BY NEWID()';
			break;

			default:
			$sql = 'SELECT *
				FROM ' . USERS_TABLE . '
				WHERE user_type <> ' . USER_IGNORE . '
				AND user_type <> ' . USER_INACTIVE . '
				ORDER BY RAND()';
			break;
		}

		$result = $db->sql_query_limit($sql, 1);
		$row = $db->sql_fetchrow($result);

        $username = $row['username'];
		$user_id = (int) $row['user_id'];
		$colour = $row['user_colour'];

		$template->assign_block_vars('random_member', array(
			'USERNAME_FULL'		=> get_username_string('full', $user_id, $username, $colour),
			'USERNAME'			=> get_username_string('username', $user_id, $username, $colour),
			'USER_COLOR'		=> get_username_string('colour', $user_id, $username, $colour),
		));
		$db->sql_freeresult($result);
Open: /styles/prosilver/template/index_body.html

Place wherever you want it ti show:

Code: Select all

<!-- BEGIN random_member -->
<p>Vote <span style="font-weight:bold; ">{random_member.USERNAME_FULL}</span> for President!</p>
<!-- END random_member -->
Screenshot:
2014-12-24 00 43 09.png

Vote for president!

Posted: 02 Oct 2012, 05:13
by martin123456

Vote for president!

Posted: 02 Oct 2012, 05:15
by Solidjeuh
martin123456 wrote:You mean this one ? viewtopic.php?f=40&t=1977&p=12679&hilit=+vote#p12679
I tried that one.. Not working on my forum..
This code is a little different, and it works.. :roll:
This one also grabs the color of the group the user is in.. :D

Vote for president!

Posted: 02 Oct 2012, 08:14
by Stoker
Code works perfect, its what I use here.
BTW, my code is also from the b3 portal random member :D

Vote for president!

Posted: 04 Oct 2012, 20:21
by Steve
No need to use a switch for database types just also use $db->build_sql_query()

Vote for president!

Posted: 05 Oct 2012, 12:01
by RMcGirr83
That switch is needed for the different databases RANDOM function which ever it may be. (ORDER BY RANDOM()';ORDER BY NEWID()';ORDER BY RAND()';)

Vote for president!

Posted: 26 Jul 2014, 09:06
by Mindful Person
Can this code show only members from a specific group?

Vote for president!

Posted: 26 Jul 2014, 12:27
by martin123456
Mindful Person wrote:Can this code show only members from a specific group?

viewtopic.php?f=40&t=1977&p=12679&hilit=+vote#p12679

Vote for president!

Posted: 26 Jul 2014, 16:11
by Mindful Person
I dont need it anymore.
Thanks anyway Martin I have found the solution.