关于一个在线访问计数器的编程实例,有一些问题。
opendata.php
    <?
if(!Mysql_connect("localhost","root","123"))
echo "连接数据库失败";
Elseif(!Mysql_select_db("mydata"))
echo "开启数据库失败";
    ?>
count.php
    
    <?
 include("opendata.php");
 $time=Date("m").Date("d");
 $sql="select * from counter where date='$time'";
 $record=Mysql_query($sql);
 Setcookie("enter","True");
 If(!Mysql_fetch_row($record))
 {
   $sql = "insert into counter(date,today,first,second,third,forth,fifth,sixth) values ('$time',0,0,0,0,0,0,0)";    
   Mysql_query($sql);
 }
 $sql="select * from counter where date='$time'";
 $record=Mysql_query($sql);
 List($date,$today,$first,$second,$third,$forth,$fifth,$sixth)=Mysql_fetch_row($record);
 $select=Floor(Date("G")/4)+1;
 $sql="select * from total";
 $record=Mysql_query($sql);
 List($total)=Mysql_fetch_row($record);
 If($enter<>"True")
 {
 $today++;
 Switch($select)
 {
  case 1: $sql="update counter set today='$today',first=first+1 where date='$time'";
          Mysql_query($sql);
          break;
  case 2: $sql="update counter set today='$today',second=second+1 where date='$time'";
          Mysql_query($sql);
          break;
  case 3: $sql="update counter set today='$today',third=third+1 where date='$time'";
          Mysql_query($sql);
          break;
  case 4: $sql="update counter set today='$today',forth=forth+1 where date='$time'";
          Mysql_query($sql);
          break;
  case 5: $sql="update counter set today='$today',fifth=fifth+1 where date='$time'";
          Mysql_query($sql);
          break;
  case 6: $sql="update counter set today='$today',sixth=sixth+1 where date='$time'";
          Mysql_query($sql);
 }
 $total++;
 $sql="update total set total=total+1";
 Mysql_query($sql);
 }
?>
<html>
<title>人数浏览统计</title>
<p align=center><img src=zct.jpg><br>
<?
$number = strlen($total);
For($i=0;$i<=$number-1;$i++)
$gif[$i] = substr($total,$i,1).".jpg";
echo "<font size=5>您是本站的第 </font>";
For($i=0;$i<=$number-1;$i++)
echo "<img src=".$gif[$i].">";
echo "<font size=5> 位上线的用户<br>";
$number = strlen($today);
For($i=0;$i<=$number-1;$i++)
$gif[$i] = substr($today,$i,1).".jpg";
echo "<font size=5>您是今天的第 </font>";
For($i=0;$i<=$number-1;$i++)
echo "<img src=".$gif[$i].">";
echo "<font size=5> 位上线的用户";
?>
<hr>
<center>
<form action=search.php method=post>
<table border=0>
<tr>
<td><font color=green>查询上线人数统计: </font></td>
<td><select size=1 name=month>
<option selected>01<option>02<option>03<option>04
<option>05<option>06<option>07<option>08<option>09
<option>10<option>11<option>12</select>月</td>
<td><select size=1 name=day>
<option selected>01<option>02<option>03<option>04
<option>05<option>06<option>07<option>08<option>09
<option>10<option>11<option>12<option>13<option>14
<option>15<option>16<option>17<option>18<option>19
<option>20<option>21<option>22<option<23><option>24
<option>25<option>26<option>27<option>28<option>29
<option>30<option>31</select>日</td><td> 
<input type=submit name=SEND value=查询></td>
</tr>
<tr>
<td colspan=4 align=center>
<a href=search.php?month=<?echo Date("m")?>&day=<?echo Date("d")?>>
<font size=3>查看今日各时段流量统计</font></a></td>
</tr>
</table>
</form>
<font color=red size=5><?echo $errmsg;?></font>
</html>search.php
       <?
include("opendata.php");

$time=$month.$day;
$sql="select * from counter where date='$time'";
$record=Mysql_query($sql);
echo $record;

#If(!Mysql_fetch_row($record))
#{
#$errmsg="此日无上线的访客,请重新查询!";
#Header("Location:count.php?errmsg=$errmsg");
#}
$sql="select * from counter where date='$time'";
$record=Mysql_query($sql);
List($date,$today,$first,$second,$third,$forth,$fifth,$sixth)=Mysql_fetch_row($record);
$p1=Sprintf("%.2f",$first/$today*100)."%";
$p2=Sprintf("%.2f",$second/$today*100)."%";
$p3=Sprintf("%.2f",$third/$today*100)."%";
$p4=Sprintf("%.2f",$forth/$today*100)."%";
$p5=Sprintf("%.2f",$fifth/$today*100)."%";
$p6=Sprintf("%.2f",$sixth/$today*100)."%";
?>
<html>
<title>各时段上线人数统计</title>
<body>
<p align=center><font color=blue size=5><?echo $month;?> 月 
<?echo $day;?> 日上线记录统计表</font>
<hr>
<font color=green size=4>各时段上线次数统计图 </font>本日上线总数: 
<?echo $today;?><br>
00-04时 <img src=bar.jpg width=<?echo $first;?> height=10> <?echo $first;?><br>
04-08时 <img src=bar.jpg width=<?echo $second;?> height=10> <?echo $second;?><br>
08-12时 <img src=bar.jpg width=<?echo $third;?> height=10> <?echo $third;?><br>
12-16时 <img src=bar.jpg width=<?echo $forth;?> height=10> <?echo $forth;?><br>
16-20时 <img src=bar.jpg width=<?echo $fifth;?> height=10> <?echo $fifth;?><br>
20-24时 <img src=bar.jpg width=<?echo $sixth;?> height=10> <?echo $sixth;?><br>
<hr> 
<font color=green size=4>各时段上线比例统计图 </font>总比例: 100%<br>
00-04时 <img src=bar.jpg width=<?echo $first/$today*600;?> height=10> 
<?echo $p1;?><br>
04-08时 <img src=bar.jpg width=<?echo $second/$today*600;?> height=10> 
<?echo $p2;?><br>
08-12时 <img src=bar.jpg width=<?echo $third/$today*600;?> height=10> 
<?echo $p3;?><br>
12-16时 <img src=bar.jpg width=<?echo $forth/$today*600;?> height=10> 
<?echo $p4;?><br>
16-20时 <img src=bar.jpg width=<?echo $fifth/$today*600;?> height=10> 
<?echo $p5;?><br>
20-24时 <img src=bar.jpg width=<?echo $sixth/$today*600;?> height=10> 
<?echo $p6;?><br>
<hr>
<center><a href=count.php>回到首页</a>
</body>
</title>
</html>当我点击count.php上面的查询或者查看时,
Warning: Division by zero in D:\root\1\search.php on line 17Warning: Division by zero in D:\root\1\search.php on line 18Warning: Division by zero in D:\root\1\search.php on line 19Warning: Division by zero in D:\root\1\search.php on line 20Warning: Division by zero in D:\root\1\search.php on line 21Warning: Division by zero in D:\root\1\search.php on line 22月 日上线记录统计表 
--------------------------------------------------------------------------------
各时段上线次数统计图 本日上线总数: 
00-04时  
04-08时  
08-12时  
12-16时  
16-20时  
20-24时  --------------------------------------------------------------------------------
各时段上线比例统计图 总比例: 100%
00-04时  Warning: Division by zero in D:\root\1\search.php on line 40
0 height=10> 0.00%
04-08时  Warning: Division by zero in D:\root\1\search.php on line 42
0 height=10> 0.00%
08-12时  Warning: Division by zero in D:\root\1\search.php on line 44
0 height=10> 0.00%
12-16时  Warning: Division by zero in D:\root\1\search.php on line 46
0 height=10> 0.00%
16-20时  Warning: Division by zero in D:\root\1\search.php on line 48
0 height=10> 0.00%
20-24时  Warning: Division by zero in D:\root\1\search.php on line 50
0 height=10> 0.00%--------------------------------------------------------------------------------回到首页 
也就说说search.php上面的数据完全没有传过去,求解答,谢谢谢谢  

解决方案 »

  1.   

    什么数据? 好乱你打印一下 echo $time;
    看里面有没值, 没值
      

  2.   


    <?php
    if(!mysql_connect("localhost","root","123")) 
       echo "连接数据库失败"; if(!mysql_select_db("mydata")) 
       echo "开启数据库失败"; 
    ?>
      

  3.   

    不是出错。。php.ini有个设置register_globals 设置为on (如果没记错的。)就不会报这样的警告了.
      

  4.   

    错误提示都是英文大白话,在线翻译一下Division by zero就知道了
      

  5.   

    楼主不懂得运用include吗晕这太长了  ⊙﹏⊙b汗