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
https://forums.phpfreaks.com/topic/19962-poll-results-solved/
Share on other sites

Have you tried running this in something like phpMyAdmin?  If so, the sql statement returned results you're looking for?

Just trying to work out if it's SQL or PHP.

Rich

[color=red]Edit: Also, if you echo things out as you go, it's a good way to diagnose.[/color]
Link to comment
https://forums.phpfreaks.com/topic/19962-poll-results-solved/#findComment-87929
Share on other sites

I've just noticed something...

If the code that you've included is all you have you're missing something massive...

[code=php:0]
<?php
  session_start(); // this must be specified at the top if you're referring to a $_SESSION variable.
?>
[/code]

Regards
Rich
Link to comment
https://forums.phpfreaks.com/topic/19962-poll-results-solved/#findComment-87936
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
https://forums.phpfreaks.com/topic/19962-poll-results-solved/#findComment-87950
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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