digitalgod Posted September 6, 2006 Share Posted September 6, 2006 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 tablespolls (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? Quote Link to comment https://forums.phpfreaks.com/topic/19962-poll-results-solved/ Share on other sites More sharing options...
digitalgod Posted September 7, 2006 Author Share Posted September 7, 2006 anyone? Quote Link to comment https://forums.phpfreaks.com/topic/19962-poll-results-solved/#findComment-87911 Share on other sites More sharing options...
HuggieBear Posted September 7, 2006 Share Posted September 7, 2006 I'm investigating :)Rich Quote Link to comment https://forums.phpfreaks.com/topic/19962-poll-results-solved/#findComment-87923 Share on other sites More sharing options...
HuggieBear Posted September 7, 2006 Share Posted September 7, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/19962-poll-results-solved/#findComment-87929 Share on other sites More sharing options...
HuggieBear Posted September 7, 2006 Share Posted September 7, 2006 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]RegardsRich Quote Link to comment https://forums.phpfreaks.com/topic/19962-poll-results-solved/#findComment-87936 Share on other sites More sharing options...
digitalgod Posted September 7, 2006 Author Share Posted September 7, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/19962-poll-results-solved/#findComment-87950 Share on other sites More sharing options...
digitalgod Posted September 7, 2006 Author Share Posted September 7, 2006 I found my error... it was the single quotes around v.answer. Thanks for your help[code]a.id = 'v.answer'[/code] Quote Link to comment https://forums.phpfreaks.com/topic/19962-poll-results-solved/#findComment-87956 Share on other sites More sharing options...
HuggieBear Posted September 7, 2006 Share Posted September 7, 2006 No problem,Didn't really help much though ;DRegardsRich Quote Link to comment https://forums.phpfreaks.com/topic/19962-poll-results-solved/#findComment-87966 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.