Jump to content
MakeWebGames

Ending a Poll Problem


Smokey

Recommended Posts

I know there are lots of little things like this "unfinished" with mccodes..but yea, when you end a poll, the winning answer does not show. Now i pinpointed why, but i am not sure how to go about it.

When you end the poll it should tally up the winner but it doesnt, here is the query to end the poll.

 

$db->query("UPDATE `polls` SET `active` = '0' WHERE `id` = {$_POST['poll']}");

 

What it SHOULD do is look in these fields 'vote1,vote2,vote3,vote4,vote5,vote6,vote7,vote8,vote9,vote10' and determine which had the greatest number of votes, then it should alter the 'winner' field in that query and put in a 1,2,3,4,5,6,7,8,9 or 10 depending on which of the vote fields is highest.

Here is the whole endpoll function:

 

function endpoll() {
global $ir, $c,$userid, $db;
	$_POST['poll'] = ( isset($_POST['poll'])&&is_numeric($_POST['poll']) )?abs(intval($_POST['poll'])):'';
         if ( empty($_POST['poll']) ) {
  echo "
Choose a poll to close
<br />
<form action='staff_polls.php?action=endpoll' method='post'>
  ";
$q = $db->query("SELECT `id`,`question` FROM `polls` WHERE `active` = '1'");
      while ( $r = $db->fetch_row($q) ) {
  echo '
<input type="radio" name="poll" value="'.$r['id'].'" /> Poll ID '.$r['id'].' - '.$r['question'].'
<br />
  ';
      }
  echo '
<input type="submit" value="Close Selected Poll" />
</form>
  ';
         } else {
$q = $db->query('SELECT `id` FROM `polls` WHERE `id` = '.$_POST['poll']);
      if ( $db->num_rows($q) == 0 ) {
  echo 'Invalid poll.<br />> <a href="staff_polls.php?action=endpoll">Go Back</a>';
  die($h->endpage());
      }      
$db->query("UPDATE `polls` SET `active` = '0' WHERE `id` = {$_POST['poll']}");
  echo 'Poll closed.<br />> <a href="staff.php">Go Home</a>';
  die($h->endpage());
         }
}

 

Any help would be appreciated.

Link to comment
Share on other sites

no, if it were a problem with that file it would still be entered into the 'winner' field in the database, which it is not. The polling.php isnt going to show a result that isnt there.

Did you happen to look at that file though poll_view.php? It is calculating the outcome, it's not updating the query so you would not see nothing in the fields differently...If you want it to update a field you will need to add it as for none of the pages actually updates that field but calculates the table fields.

Link to comment
Share on other sites

I see what you're saying, to be honest it confuses me.

 

$q=$db->query("SELECT * FROM polls WHERE active='0' ORDER BY id desc");
if ( ! $db->num_rows($q) )
{
die("<b>There are no finished polls right now</b>");
}
while ($r=$db->fetch_row($q))
{
echo "<table width='80%' style='border:3px solid #A39B83;' align='center' cellspacing='0' cellpadding='5'><tr style='background-color:#B8B8B8;'> <th width='45%'>Choice</th> <th width='10%'>Votes</th> <th width='15%'>Bar</th> <th width='10%'>Percentage</th> </tr> <tr style='background-color:#CCCCCC;'> <th colspan='4'><font color='firebrick'>{$r['question']}</font></th> </tr>";
for ( $i=1; $i <= 10; $i++)
{
if ( $r['choice'.$i])
{
$k='choice'.$i;
$ke='voted'.$i;
if ( $r['votes'] != 0) {
$perc=number_format($r[$ke]/$r['votes']*100, 2);
} else { $perc=0; }
echo "<tr style='background-color:#CCCCCC;'> <td align='left'>{$r[$k]}</td> <td align='left'>{$r[$ke]}</td> <td align='left'><img src='bargreen.gif' alt='Bar' width='$perc' height='10' /></td> <td align='right'>$perc%</td></tr>";
}
}
echo "<tr style='background-color:#CCCCCC;'><th colspan='4'>Total Votes: {$r['votes']}</th></tr>
<tr style='background-color:#B8B8B8;'><th colspan='4'>Outcome: ".$r['choice'.$r['winner']]."</th></tr>
</table><br />";
}
Link to comment
Share on other sites

  • 1 year later...

dont find answer to this question to

we need to compare all this

 

vote1,vote2,vote3,vote4,vote5,vote6,vote7,vote8,vote9,vote10

 

and select high value and associate to

 

choice1,choice2,choice3,choice4,choice5,choice6,choice7,choice8,choice9,choice10

 

and enter choice with more vote in winner field. But i dont know how to do it.

I know max() is for column but i this case i don't know how do it

anyone can help ?

Thanks

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...