Jump to content


Photo

poll results *SOLVED*


  • Please log in to reply
7 replies to this topic

#1 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 06 September 2006 - 11:10 PM

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

<?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>";
?>

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

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

any reasons why?

#2 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 07 September 2006 - 06:56 PM

anyone?

#3 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 07 September 2006 - 07:07 PM

I'm investigating :)

Rich
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#4 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 07 September 2006 - 07:17 PM

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

Edit: Also, if you echo things out as you go, it's a good way to diagnose.
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#5 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 07 September 2006 - 07:27 PM

I've just noticed something...

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

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

Regards
Rich
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#6 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 07 September 2006 - 07:57 PM

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

#7 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 07 September 2006 - 08:02 PM

I found my error... it was the single quotes around v.answer. Thanks for your help
a.id = 'v.answer'


#8 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 07 September 2006 - 08:15 PM

No problem,

Didn't really help much though  ;D

Regards
Rich
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users