View previous topic :: View next topic |
Author |
Message |
some random person -
Joined: 06 Oct 2003 Posts: 128 Location: I live here! At my house!
|
Posted: Mon Apr 19, 2004 8:36 pm Post subject: Help with poll script |
|
|
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 |
|
 |
aprelium -
Joined: 22 Mar 2002 Posts: 6800
|
Posted: Wed Apr 21, 2004 1:35 pm Post subject: Re: Help with poll script |
|
|
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 |
|
 |
some random person -
Joined: 06 Oct 2003 Posts: 128 Location: I live here! At my house!
|
Posted: Thu Apr 22, 2004 12:48 am Post subject: |
|
|
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 |
|
 |
aprelium -
Joined: 22 Mar 2002 Posts: 6800
|
Posted: Fri Apr 23, 2004 2:49 pm Post subject: |
|
|
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 |
|
 |
|