RE: [PHP] Division by zero
| From: | John W. Holmes | Date: | Tue, 08 Oct 2002 01:42:39 +0000 |
| Subject: | RE: [PHP] Division by zero | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-119180@lists.php.net to get a copy of this message | ||
Sounds like $total is zero to me...do you think PHP is making up errors
for you? Have you checked the value of $total and the different $voteX
variables?
---John Holmes...
> -----Original Message-----
> From: Gary [mailto:garyb10@earthlink.net]
> Sent: Monday, October 07, 2002 9:29 PM
> To: php-general@lists.php.net
> Subject: [PHP] Division by zero
>
> I am trying t get the percent of votes form the table poll, but keep
> getting Division by zero for the line commented below.
>
> <snip>
> if ($res) {
> echo "bla bla bla";
> $sql = "SELECT question, responce1, responce2, responce3,
> vote1, vote2, vote3, date FROM poll WHERE id = {$_POST['id']}";
> $res = $db->query($sql);
> if (DB::isError($res)) {
> die ($res->getMessage());
> }
> while ($row = $res->fetchRow());
> $id = $row[0];
> $question = $row[1];
> $responce1 = $row[2];
> $responce2 = $row[3];
> $responce3 = $row[4];
> $vote1 = $row[5];
> $vote2 = $row[6];
> $vote3 = $row[7];
> $date = $row[8];
>
> /* Count the votes*/
> $total = $vote1 + $vote2 + $vote3;
>
> /* Caluclate */
> $perc_vote1 = round(($vote1/$total)*100,2); /* Division by zero*/
> $perc_vote2 = round(($vote2/$total)*100,2); /* Division by zero*/
> $perc_vote3 = round(($vote3/$total)*100,2); /* Division by zero*/
>
>
> <snip>
>
> TIA
> Gary
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php