swfcfan4 Posted November 30, 2009 Share Posted November 30, 2009 Hi everyone! I am new to this forum, heard if was a great forum so I thought I'd join and ask a question so here goes! I am having a little problem thinking about how to display a vote count for a web poll after a deadline has passed. I have created the web form in HTML and used the POST method to retrieve the vote from the HTML web form. I have saved the voter's selection into a text file and have a warning in place if they have voted before using a session cookie. My only problem is how to display the final result of the vote in a vote count. I can give you a sample of my code: session_start (); $_SESSION["previousVisit"] = time(); if ($_SESSION["previousVisit"]) { echo "NO VOTING TWICE!!!"; } else { $sels = $_POST['selection']; echo "Every vote counts, you selected"; echo "$vote"<br />"; } $filePointer = fopen ("Num_of_votes.txt", "a"); if ($filePointer) { $selct = $_POST['selection']; $nln = "\n" ; $line = $selct .$nln ; fputs ($filePointer, $line); } fclose ($filePointer); Any help would be very much appreciated and I thank you in advance if you are able to help me with my problem. Quote Link to comment https://forums.phpfreaks.com/topic/183455-help-to-display-a-vote-count-after-a-deadline-has-passed/ Share on other sites More sharing options...
rajivgonsalves Posted November 30, 2009 Share Posted November 30, 2009 something like this should work foreach (array_count_values(file("Num_of_votes.txt")) as $selection => $count) { echo $selection . ' - ' . $count . '<br />'; } Quote Link to comment https://forums.phpfreaks.com/topic/183455-help-to-display-a-vote-count-after-a-deadline-has-passed/#findComment-968372 Share on other sites More sharing options...
swfcfan4 Posted November 30, 2009 Author Share Posted November 30, 2009 Sorry to say that what you gave me did not work it is outputting results like this: Alan ShearerMichael OwenKevin PressmanDavid GinolaAlan Shearer - 1 Is there any thing else that can be done? Quote Link to comment https://forums.phpfreaks.com/topic/183455-help-to-display-a-vote-count-after-a-deadline-has-passed/#findComment-968408 Share on other sites More sharing options...
swfcfan4 Posted November 30, 2009 Author Share Posted November 30, 2009 Actually, going back and looking at my code, I have realised where I went wrong, and the code you gave me worked! Thanks very much. Quote Link to comment https://forums.phpfreaks.com/topic/183455-help-to-display-a-vote-count-after-a-deadline-has-passed/#findComment-968426 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.