poll script problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
cheatboy00
Forum Contributor
Posts: 151
Joined: Sat Jun 29, 2002 10:36 am
Location: canada
Contact:

Post by cheatboy00 »

$len1 = mysql_query("select count(*) from poll where vote == 1");
$len2 = mysql_query("select count(*) from poll where vote == 2");
$len3 = mysql_query("select count(*) from poll where vote == 3");

$sum = $len1 + $len2 + $len3;

$onepre = (@($len1 / $sum) * 100);
$twopre = (@($len2 / $sum) * 100);
$twopre = (@($len3 / $sum) * 100);

thats what i have now but the numbers dont show its all just zeros....

http://dragonsblood.nicewebshost.com/cbaa/showresults.php

and for votes i voted a couple of times for 1 (which is the first option)

btw .... thanks for all the help, so far.
Galahad
Forum Contributor
Posts: 111
Joined: Fri Jun 14, 2002 5:50 pm

Post by Galahad »

Try this:

Code: Select all

$len1 = mysql_query("select count(*) from poll where vote = 1");
You use the = in mysql, but need == for compares in php. So if you wanted to do something like:

Code: Select all

if ($x == 10) dosomething();
you need the '=='. But for a mysql query like the one above, you just use '='. Sorry about the confusion with that. I hope this works.
User avatar
llimllib
Moderator
Posts: 466
Joined: Mon Jul 01, 2002 2:19 pm
Location: Baltimore, MD

Post by llimllib »

so far, you've only got handles to the results of the queries. After that, you need

Code: Select all

$result1 = mysql_fetch_row($len1);
$numberOfVotesForOne = $result1ї0]
and so on for the rest of the handles
Wandrer
Forum Newbie
Posts: 21
Joined: Thu Jun 06, 2002 8:43 am

Post by Wandrer »

Not sure if this will help, but thought I would offer it anyway:

http://paul.the-pearsons.net/PHPVotingBooth2.05.zip
User avatar
cheatboy00
Forum Contributor
Posts: 151
Joined: Sat Jun 29, 2002 10:36 am
Location: canada
Contact:

Post by cheatboy00 »

WOW.............. a round of aplause for all my wonderful helpers thanks

its now working....
Post Reply