TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,970
  • Latest: bynw
Stats
  • Total Posts: 196,055
  • Total Topics: 21,337
  • Online today: 201
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 147
  • Total: 147

Polls and who voted

Started by JayT, August 01, 2006, 01:24:29 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

JayT

Well, I got a script from SMF that makes a form to pull DB info to see who voted in a poll. Here is the link to the script.

Below is the script but the I get an error message when I try to run it. Here is the error: Fatal error: Unknown function: tp_loadtheme() in /Sources/Load.php on line 1037. Any ideas to fix this?


<?php
require_once(
"SSI.php");
if ( !$user_info['is_admin'] )
redirectexit();

if ( isset($_POST['act']) && $_POST['act'] == 'display' )
{
if ( empty($_POST['topics']) )
$cond = "1";
else
$cond = "FIND_IN_SET(t.ID_TOPIC, '" . implode(',',explode(',',$_POST['topics'])) . "')";
// get the polls
$res = db_query("
SELECT
p.ID_POLL, p.question
FROM (
{$db_prefix}topics AS t, {$db_prefix}polls AS p)
WHERE t.ID_POLL = p.ID_POLL
AND
$cond
"
, __FILE__, __LINE__);
$polls = array(); $pollIds = array();
while ( $row = mysql_fetch_assoc($res) )
{
$polls[$row['ID_POLL']] = $row;
$polls[$row['ID_POLL']]['votes'] = array();
$pollIds[] = $row['ID_POLL'];
}
mysql_free_result($res);

if ( empty($polls) )
die("No polls in those topics");
// get the votes
$res = db_query("
SELECT mem.ID_MEMBER, mem.realName, pc.label, lp.ID_POLL
FROM
{$db_prefix}log_polls AS lp
LEFT JOIN
{$db_prefix}members AS mem ON lp.ID_MEMBER = mem.ID_MEMBER
LEFT JOIN
{$db_prefix}poll_choices AS pc ON (lp.ID_CHOICE = pc.ID_CHOICE AND lp.ID_POLL=pc.ID_POLL)
WHERE FIND_IN_SET(lp.ID_POLL, '"
.implode(',',$pollIds)."')
"
, __FILE__, __LINE__);
while ( $row = mysql_fetch_assoc($res) )
$polls[$row['ID_POLL']]['votes'][] = $row;
mysql_free_result($res);

foreach($polls AS $poll)
{
echo '
<table border="1">
<caption>'
, $poll['question'], '</caption>
<tr>
<td align="center">Voted For</td>
<td align="center">By Member</td>
</tr>'
;
if ( empty($poll['votes']) )
echo '
<tr>
<td colspan="2" align="center">No members voted for this poll</td>
</tr>'
;
foreach($poll['votes'] AS $vote)
{
echo '
<tr>
<td align="center">'
, $vote['label'], '</td>
<td align="center"><a href="'
, $scripturl, '?action=profile;u=', $vote['ID_MEMBER'], '">', $vote['realName'], '</a></td>
</tr>'
;
}
echo '
</table>
<br/>
<br/>'
;
}
}
else
{
// create a form in wish they can input the topics
echo '
<form action="'
, $_SERVER['PHP_SELF'], '" method="post" >
<input type="hidden" name="act" value="display" />
Input the topics you want to display the polls for in a comma (,) delimited format <br/>
(i.e:  1,5,99,2058,63940,2) (Leave blank for ALL) <br/>
<input type="text" name="topics" size="100" /> <br/>
<input type="submit" value="Show Polls" />
</form>'
;
}
?>

Xarcell


G6Cad

Where do you run the script from?
In a block or article?    If so, remove the php tags <?php and ?> (start and end) and see if you get it working

Crip

That script should be added in a phpbox.
I have become comfortably numb!

Cripzone | Crip's Free 2.0.2 Themes



JayT

That script goes in a php file that is ran from the forum root. However, it doesn't work that way, in a php article or a phpbox block. I am posting here because it seems to be an issue with TP because it works on a regular SMF forum.

G6Cad

Perhaps try to put in
global $scripturl;
in the start of the script for the php block you have ?

JayT

Keeps taking me to an error page saying the page isn't redirecting properly.

G6Cad

Do you have the correct url set up for where the script should find it?

G6Cad

Just to be sure, is this the code you are using now ?  With out the <?php and ?>


global $scripturl;
require_once("SSI.php");
if ( !$user_info['is_admin'] )
redirectexit();

if ( isset($_POST['act']) && $_POST['act'] == 'display' )
{
if ( empty($_POST['topics']) )
$cond = "1";
else
$cond = "FIND_IN_SET(t.ID_TOPIC, '" . implode(',',explode(',',$_POST['topics'])) . "')";
// get the polls
$res = db_query("
SELECT
p.ID_POLL, p.question
FROM ({$db_prefix}topics AS t, {$db_prefix}polls AS p)
WHERE t.ID_POLL = p.ID_POLL
AND $cond
", __FILE__, __LINE__);
$polls = array(); $pollIds = array();
while ( $row = mysql_fetch_assoc($res) )
{
$polls[$row['ID_POLL']] = $row;
$polls[$row['ID_POLL']]['votes'] = array();
$pollIds[] = $row['ID_POLL'];
}
mysql_free_result($res);

if ( empty($polls) )
die("No polls in those topics");
// get the votes
$res = db_query("
SELECT mem.ID_MEMBER, mem.realName, pc.label, lp.ID_POLL
FROM {$db_prefix}log_polls AS lp
LEFT JOIN {$db_prefix}members AS mem ON lp.ID_MEMBER = mem.ID_MEMBER
LEFT JOIN {$db_prefix}poll_choices AS pc ON (lp.ID_CHOICE = pc.ID_CHOICE AND lp.ID_POLL=pc.ID_POLL)
WHERE FIND_IN_SET(lp.ID_POLL, '".implode(',',$pollIds)."')
", __FILE__, __LINE__);
while ( $row = mysql_fetch_assoc($res) )
$polls[$row['ID_POLL']]['votes'][] = $row;
mysql_free_result($res);

foreach($polls AS $poll)
{
echo '
<table border="1">
<caption>', $poll['question'], '</caption>
<tr>
<td align="center">Voted For</td>
<td align="center">By Member</td>
</tr>';
if ( empty($poll['votes']) )
echo '
<tr>
<td colspan="2" align="center">No members voted for this poll</td>
</tr>';
foreach($poll['votes'] AS $vote)
{
echo '
<tr>
<td align="center">', $vote['label'], '</td>
<td align="center"><a href="', $scripturl, '?action=profile;u=', $vote['ID_MEMBER'], '">', $vote['realName'], '</a></td>
</tr>';
}
echo '
</table>
<br/>
<br/>';
}
}
else
{
// create a form in wish they can input the topics
echo '
<form action="', $_SERVER['PHP_SELF'], '" method="post" >
<input type="hidden" name="act" value="display" />
Input the topics you want to display the polls for in a comma (,) delimited format <br/>
(i.e:  1,5,99,2058,63940,2) (Leave blank for ALL) <br/>
<input type="text" name="topics" size="100" /> <br/>
<input type="submit" value="Show Polls" />
</form>';
}

JayT

Quote from: G6 on August 01, 2006, 10:31:25 PM
Do you have the correct url set up for where the script should find it?

Umm, not sure.
Quote from: G6 on August 01, 2006, 10:34:11 PM
Just to be sure, is this the code you are using now ?  With out the <?php and ?>


global $scripturl;
require_once("SSI.php");
if ( !$user_info['is_admin'] )
redirectexit();

if ( isset($_POST['act']) && $_POST['act'] == 'display' )
{
if ( empty($_POST['topics']) )
$cond = "1";
else
$cond = "FIND_IN_SET(t.ID_TOPIC, '" . implode(',',explode(',',$_POST['topics'])) . "')";
// get the polls
$res = db_query("
SELECT
p.ID_POLL, p.question
FROM ({$db_prefix}topics AS t, {$db_prefix}polls AS p)
WHERE t.ID_POLL = p.ID_POLL
AND $cond
", __FILE__, __LINE__);
$polls = array(); $pollIds = array();
while ( $row = mysql_fetch_assoc($res) )
{
$polls[$row['ID_POLL']] = $row;
$polls[$row['ID_POLL']]['votes'] = array();
$pollIds[] = $row['ID_POLL'];
}
mysql_free_result($res);

if ( empty($polls) )
die("No polls in those topics");
// get the votes
$res = db_query("
SELECT mem.ID_MEMBER, mem.realName, pc.label, lp.ID_POLL
FROM {$db_prefix}log_polls AS lp
LEFT JOIN {$db_prefix}members AS mem ON lp.ID_MEMBER = mem.ID_MEMBER
LEFT JOIN {$db_prefix}poll_choices AS pc ON (lp.ID_CHOICE = pc.ID_CHOICE AND lp.ID_POLL=pc.ID_POLL)
WHERE FIND_IN_SET(lp.ID_POLL, '".implode(',',$pollIds)."')
", __FILE__, __LINE__);
while ( $row = mysql_fetch_assoc($res) )
$polls[$row['ID_POLL']]['votes'][] = $row;
mysql_free_result($res);

foreach($polls AS $poll)
{
echo '
<table border="1">
<caption>', $poll['question'], '</caption>
<tr>
<td align="center">Voted For</td>
<td align="center">By Member</td>
</tr>';
if ( empty($poll['votes']) )
echo '
<tr>
<td colspan="2" align="center">No members voted for this poll</td>
</tr>';
foreach($poll['votes'] AS $vote)
{
echo '
<tr>
<td align="center">', $vote['label'], '</td>
<td align="center"><a href="', $scripturl, '?action=profile;u=', $vote['ID_MEMBER'], '">', $vote['realName'], '</a></td>
</tr>';
}
echo '
</table>
<br/>
<br/>';
}
}
else
{
// create a form in wish they can input the topics
echo '
<form action="', $_SERVER['PHP_SELF'], '" method="post" >
<input type="hidden" name="act" value="display" />
Input the topics you want to display the polls for in a comma (,) delimited format <br/>
(i.e:  1,5,99,2058,63940,2) (Leave blank for ALL) <br/>
<input type="text" name="topics" size="100" /> <br/>
<input type="submit" value="Show Polls" />
</form>';
}


Yes, I took out the php

This website is proudly hosted on Crocweb Cloud Website Hosting.