Help with poll script

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
some random person
-


Joined: 06 Oct 2003
Posts: 128
Location: I live here! At my house!

PostPosted: Mon Apr 19, 2004 8:36 pm    Post subject: Help with poll script Reply with quote

I'm working on a poll script, and for the one part I need to add up all the votes.

Heres the code for it:

Code:

//Mind this array for now...
$poll_option = array(
         '1' => 'poll_option_1',
           '2' => 'poll_option_2',
             '3' => 'poll_option_3',
           '4' => 'poll_option_4',
         '5' => 'poll_option_5',
        );

$poll_votes = array(
         '1' => 'option_1_votes',
           '2' => 'option_2_votes',
             '3' => 'option_3_votes',
           '4' => 'option_4_votes',
         '5' => 'option_5_votes',
        );

$poll_info = array(
         'options' => $poll_option,
         'num_votes' => $poll_votes,
);

$total = "0";

$increase_var_1 = "0";

$array_num = "1";

$sql_result = mysql_result($edit_sql_poll, 0, $poll_info['num_votes'][$array_num]);

while(mysql_result($edit_sql_poll, 0,"num_choices") > $increase_var_1) {

$total + $sql_result;

$increase_var_1++;
$array_num++;

}

For some reason the value of $total is always 0... It seems easy enough.[/code]
_________________
New image comming soon...

Image hosted by abyss powered website
Image copyright some random person (I made it......)
Abyss > Apache (Meaning abyss is better than apache)
My site powered by abyss->(Undergoing construction)
Back to top View user's profile Send private message
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Wed Apr 21, 2004 1:35 pm    Post subject: Re: Help with poll script Reply with quote

This line does nothing:
Code:

$total + $sql_result;


We guess that you meant:

Code:

$total += $sql_result;

_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
some random person
-


Joined: 06 Oct 2003
Posts: 128
Location: I live here! At my house!

PostPosted: Thu Apr 22, 2004 12:48 am    Post subject: Reply with quote

That worked, but the number of votes are higher then they should be. Theres only 36 and it says theres 132.
_________________
New image comming soon...

Image hosted by abyss powered website
Image copyright some random person (I made it......)
Abyss > Apache (Meaning abyss is better than apache)
My site powered by abyss->(Undergoing construction)
Back to top View user's profile Send private message
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Fri Apr 23, 2004 2:49 pm    Post subject: Reply with quote

some random person,

There is another problem with your code. You are using strings instead of integers. So replace:

Code:
$total = "0";

$increase_var_1 = "0";

$array_num = "1";

$sql_result = mysql_result($edit_sql_poll, 0, $poll_info['num_votes'][$array_num]);


with

Code:
$total = 0;

$increase_var_1 = 0;

$array_num = 1;

$sql_result = intval(mysql_result($edit_sql_poll, 0, $poll_info['num_votes'][$array_num]));

_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group