Jump to content

poll results *SOLVED*


digitalgod

Recommended Posts

hey guys,

for some reason my poll results always show up as 0 no matter what... I'm not sure where the problem is... so this is what I have

[code]
<?php
$result = mysql_query("SELECT answer FROM mtlguest_pollanswers WHERE question = '".$_SESSION['pnum']."'");
   
    while ($row = mysql_fetch_assoc($result)) {
        $allanswers[] = $row['answer'];
    }
       
    $ans_result = mysql_query("SELECT v.answer, COUNT(v.id) AS numVotes, a.answer FROM pollvotes v, pollanswers a WHERE v.question = '".$_SESSION['pnum']."' AND a.id = 'v.answer' GROUP BY v.answer ORDER BY NumVotes DESC");
    echo "<UL>";
   
    $votedvotes = array();
    while ($row2 = mysql_fetch_assoc($ans_result)) {
        extract($row2, EXTR_PREFIX_ALL, 'poll');
        $votedvotes[] = $poll_answer;
        echo "<LI>".$poll_answer.": ".$poll_numVotes."</LI>";
    }
   
    $notvotedanswers = array_diff($allanswers, $votedvotes);
    foreach($notvotedanswers as $answer) {
        echo "<LI>".$answer.": 0</LI>";
    }
   
    echo "</UL>";
?>
[/code]

here are my tables

polls (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, question VARCHAR(250))
pollanswers (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, question INT, answer VARCHAR(250))
pollvotes (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, question INT, answer INT, ip VARCHAR(20))

for some reason it never displays anything in there

[code=php:0]
while ($row2 = mysql_fetch_assoc($ans_result)) {
        extract($row2, EXTR_PREFIX_ALL, 'poll');
        $votedvotes[] = $poll_answer;
        echo "<LI>".$poll_answer.": ".$poll_numVotes."</LI>";
    }
[/code]

any reasons why?
Link to comment
Share on other sites

the part I gave you is the whole script for my poll results, session_start() had already been declared.

I already echoed out the $ans_result query and everything seems to be in order... I get no errors but for some reason the while statement isn't fired up....

I'll give it a shot in phpmyadmin and post back
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.