我想顯示與count和count不同的顯示。我的代碼在下面給出,但它顯示警告:在filename.php中除零。通過零警告進行故障排除劃分
<?php
include("db.php");
if($_POST['id'])
{
$id=mysql_escape_String($_POST['id']);
$name=mysql_escape_String($_POST['name']);
mysql_query("update messages set $name=$name+1 where id='$id'");
$result=mysql_query("select up,down from messages where id='$id'");
$row=mysql_fetch_array($result);
$up_value=$row['up'];
$down_value=$row['down'];
$total=$up_value+$down_value;
$up_per=($up_value*100)/$total;
$down_per=($down_value*100)/$total;
?>
<div style="margin-bottom:10px">
<b>Ratings for this blog</b> (<?php echo $total; ?> total)
</div>
<table width="700px">
<tr>
<td width="30px"></td>
<td width="60px"><?php echo $up_value; ?></td>
<td width="600px"><div id="greebar" style="width:<?php echo $up_per; ?>%"></div></td>
</tr>
<tr>
<td width="30px"></td>
<td width="60px"><?php echo $down_value; ?></td>
<td width="600px"><div id="redbar" style="width:<?php echo $down_per; ?>%"></div></td>
</tr>
</table>
<?php
}
?>
「這樣做對我」的問題被皺起眉頭,你應該顯示http://WhatHaveYouTried.com並問路。在主題上,你唯一的分區是'/ $ total',所以'$ total'等於'0'很明顯。你必須找出爲什麼會發生這種行爲,並防止它被0除。簡單如此。 –
你認爲$總數可能爲零嗎? –