Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 10th, 2005, 8:49 AM   #1
sam1
Newbie
 
Join Date: Nov 2004
Posts: 9
Rep Power: 0 sam1 is on a distinguished road
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);
sam1 is offline   Reply With Quote
Old Jan 10th, 2005, 9:49 AM   #2
Dizzutch
Professional Programmer
 
Dizzutch's Avatar
 
Join Date: Dec 2004
Location: Worcester, MA
Posts: 441
Rep Power: 4 Dizzutch is on a distinguished road
Send a message via ICQ to Dizzutch Send a message via AIM to Dizzutch Send a message via MSN to Dizzutch Send a message via Yahoo to Dizzutch
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?
__________________
naked pictures of you | PFO F@H stats
Dizzutch is offline   Reply With Quote
Old Jan 10th, 2005, 9:58 AM   #3
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
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.
Pizentios is offline   Reply With Quote
Old Jan 10th, 2005, 10:34 AM   #4
Dizzutch
Professional Programmer
 
Dizzutch's Avatar
 
Join Date: Dec 2004
Location: Worcester, MA
Posts: 441
Rep Power: 4 Dizzutch is on a distinguished road
Send a message via ICQ to Dizzutch Send a message via AIM to Dizzutch Send a message via MSN to Dizzutch Send a message via Yahoo to Dizzutch
Ah, that's what he meant probably
__________________
naked pictures of you | PFO F@H stats
Dizzutch is offline   Reply With Quote
Old Jan 11th, 2005, 10:15 AM   #5
sam1
Newbie
 
Join Date: Nov 2004
Posts: 9
Rep Power: 0 sam1 is on a distinguished road
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
sam1 is offline   Reply With Quote
Old Jan 11th, 2005, 10:34 AM   #6
Dizzutch
Professional Programmer
 
Dizzutch's Avatar
 
Join Date: Dec 2004
Location: Worcester, MA
Posts: 441
Rep Power: 4 Dizzutch is on a distinguished road
Send a message via ICQ to Dizzutch Send a message via AIM to Dizzutch Send a message via MSN to Dizzutch Send a message via Yahoo to Dizzutch
it's fEOf, not fOEf
[url]http://us4.php.net/manual/en/function.feof.php[url]
__________________
naked pictures of you | PFO F@H stats
Dizzutch is offline   Reply With Quote
Old Jan 11th, 2005, 10:44 AM   #7
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
sorry that was my fault, typo.
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Old Jan 11th, 2005, 10:46 AM   #8
Dizzutch
Professional Programmer
 
Dizzutch's Avatar
 
Join Date: Dec 2004
Location: Worcester, MA
Posts: 441
Rep Power: 4 Dizzutch is on a distinguished road
Send a message via ICQ to Dizzutch Send a message via AIM to Dizzutch Send a message via MSN to Dizzutch Send a message via Yahoo to Dizzutch
seriously dude, gotta get it straight man, can't afford these kinds of 'slip-ups' our reputation's on the line..:-D
__________________
naked pictures of you | PFO F@H stats
Dizzutch is offline   Reply With Quote
Old Jan 11th, 2005, 11:18 AM   #9
sam1
Newbie
 
Join Date: Nov 2004
Posts: 9
Rep Power: 0 sam1 is on a distinguished road
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");

}
}
sam1 is offline   Reply With Quote
Old Jan 11th, 2005, 11:52 AM   #10
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
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!
Pizentios is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:57 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC