![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2004
Posts: 9
Rep Power: 0
![]() |
help guys?
ok i have done the poll voting in html and php i used txt file to store the votes each vote is seperated by "|" but the thing is now when someone votes only the firse web site gets the vote.
the txt file is like this 0|0|0|0| and here is the code for it: $voting=fopen($votes, "r"); $eachvote=fgets($voting, 255); $onevote=explode("|", $eachvote); fclose($voting); |
|
|
|
|
|
#2 |
|
Professional Programmer
|
what do you mean with "only the first web site gets the vote"? Can there only be voted once? Or does the voting start at 0 in stead of at 1? What's the code you have to write to the file?
edit: oh and what are field names? 0|0|0|0 is that 0 voted for the first website, 0 voted for the second website, 0 votes for the third website, and 0 voted for the fourth website? |
|
|
|
|
|
#3 |
|
Programming Guru
![]() ![]() |
do you mean that you are only seeing one of the votes? cause explode will create a array. Or you could dump it into a list. but an array would be more usful for you. so you just need to make $onevote a dynamic array, fill it and then count it For more info on what explode can do, read the php function reference. Also, with the code above, your only reading in the first line. You'll have to do some looping with another array. so like this:
[php] //Lets say there are five options $voting=fopen($votes, "r"); $x = 0; while (!foef($voting)) { $eachvote[$x]=fgets($voting, 255); } fclose($voting); $optionone = explode("|", $eachvote[0]); $optiontwo = explode("|", $eachvote[1]); $optionthree = explode("|", $eachvote[2]); $optionfour = explode("|", $eachvote[3]); $optionfive = explode("|", $eachvote[4]); //now to count the nomber of votes for each: $votes[0] = count($optionone); $votes[1] = count($optiontwo); $votes[2] = count($optionthree); $votes[3] = count($optionfour); $votes[4] = count($optionfive); [/php] then you'd just output the $vote() array as you see fit. To get a more dynamic script you could use Varible Varibles. Documentation on that subject can be found HERE good luck, hope i helped.
__________________
Profanity is the one language that all programmers understand. Check out my Blog <---updated Nov 30 2007! Last edited by Pizentios; Jan 10th, 2005 at 11:29 AM. |
|
|
|
|
|
#4 |
|
Professional Programmer
|
Ah, that's what he meant probably
|
|
|
|
|
|
#5 |
|
Newbie
Join Date: Nov 2004
Posts: 9
Rep Power: 0
![]() |
i tried ur code now i get this error:
Fatal error: Call to undefined function: foef() in /home/eland/ub/k3004/w0308965/public_html/se517/cwk2/poll1/results.php on line 13 |
|
|
|
|
|
#6 |
|
Professional Programmer
|
it's fEOf, not fOEf
[url]http://us4.php.net/manual/en/function.feof.php[url] |
|
|
|
|
|
#7 |
|
Programming Guru
![]() ![]() |
sorry that was my fault, typo.
__________________
Profanity is the one language that all programmers understand. Check out my Blog <---updated Nov 30 2007! |
|
|
|
|
|
#8 |
|
Professional Programmer
|
seriously dude, gotta get it straight man, can't afford these kinds of 'slip-ups' our reputation's on the line..:-D
|
|
|
|
|
|
#9 |
|
Newbie
Join Date: Nov 2004
Posts: 9
Rep Power: 0
![]() |
i inputed ur code at top of this and still it gives me the same results can u checck what is wrong with this:
$f=fopen($votes, "w"); for ($i=0; $i<=count($d)-1; $i++) { if ($i == $votes) { $onevote[$i]+=1; $optiontwo[$i]+=1; $optionthree[$i]+=1; $optionfour[$i]+=1; } fputs($f, "$onevote[$i]|"); //fputs($f, "$optiontwo[$i]|"); // fputs($f, "$optionthree[$i]|"); //fputs($f, "$optionfour[$i]|"); } fclose($f); // setcookie("survey", "voted"); } } |
|
|
|
|
|
#10 |
|
Programming Guru
![]() ![]() |
can you post all of the code from the page, and use the php code tags for niffty code highlighting.
anyways, $votes is a text file right? And $i is a integer. So from the way that i read it, your if statment in the for loop never get run. Also i am not sure if i understand why your putting the count into the text file that you are reading from. If you post all of your code we'll be able to help you better.
__________________
Profanity is the one language that all programmers understand. Check out my Blog <---updated Nov 30 2007! |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|