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: 572
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 164
  • Total: 164

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.

G6Cad

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

This is the part of the code i wonder if you have set correct for the polls on your site

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/>

JayT

At this point I am clueless. I went ahead and posted on the thread over at SMF. Maybe Thantos can figure it out.

IchBin

#12
Here you go. This will display to anyone, so make sure you hide the block from other membergroups if you don't want people to see it.


require_once("SSI.php");
global $scripturl;
//if ( !$user_info['is_admin'] )
// redirectexit();
$db_prefix = 'smf_';
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>';
}


Also don't forget to set $db_prefix = 'smf_'; to your database prefix.

JayT

Thanks Ichbin.

What did you do?

IchBin

I played with it until I got it to work. lol
First thing I thought was that the admin check was unecessary if its used inside TP so I commented that out. Then when I ran it, it said that a certain table wasn't found. So I looked for the table reference and decided to try and set the $db_prefix variable since it didn't seemed to be working right. After that it seemed to work fine. :)

JayT

Cool, well I guess this could be moved to the block codes.

IchBin


Max


intresting script... anyone know how to link the polls to the topics?

Crip

IchBinâââ,¬Å¾Ã,¢..you....you, code monkey ;D
I have become comfortably numb!

Cripzone | Crip's Free 2.0.2 Themes



This website is proudly hosted on Crocweb Cloud Website Hosting.