【发布时间】:2013-06-04 22:57:03
【问题描述】:
我已经下载了本教程http://megarush.net/5-star-rating-system-with-php-mysql-jquery-and-ajax/,但出现以下错误:
注意:未定义变量:C:\xampp\htdocs\rating\rating.php 第 37 行中的 rat
注意:未定义的变量:C:\xampp\htdocs\rating\rating.php 中第 41 行的 v
<?php
include("settings.php");
connect();
$ids=array(1,2,3);
?>
<html>
<head>
<script src="jquery.js" type="text/javascript"></script>
<link rel="stylesheet" href="rating.css" />
<script type="text/javascript" src="rating.js"></script>
</head>
<body>
<?php
for($i=0;$i<count($ids);$i++)
{
$rating_tableName = 'ratings';
$id=$ids[$i];
$q="SELECT total_votes, total_value FROM $rating_tableName WHERE id=$id";
$r=mysql_query($q);
if(!$r) echo mysql_error();
while($row=mysql_fetch_array($r))
{
$v=$row['total_votes'];
$tv=$row['total_value'];
$rat=$tv/$v;
}
$j=$i+1;
$id=$ids[$i];
echo'<div class="product">
Rate Item '.$j.'
<div id="rating_'.$id.'" class="ratings">';
for($k=1;$k<6;$k++){
if($rat+0.5>$k)$class="star_".$k." ratings_stars ratings_vote";
else $class="star_".$k." ratings_stars ratings_blank";
echo '<div class="'.$class.'"></div>';
}
echo' <div class="total_votes"><p class="voted"> Rating: <strong>'.@number_format($rat).'</strong>/5 ('.$v. ' vote(s) cast)
</div>
</div></div>';}
?>
</body></html>
【问题讨论】:
-
请不要忘记提及您正在使用的框架(我编辑了这个问题的标签以反映您的)。这很重要,因为 stackoverflow 的标签过滤系统依赖于此。谢谢。
-
能否回显
$q并确认是否有返回行?如果记录集为空,$rat将不会被初始化。 (同样适用于$v) -
我做到了,它告诉我:SELECT total_votes, total_value FROM rating WHERE id=1
-
好的,我想你也在你的mysql客户端中手动检查了这个查询?我认为无论如何都应该初始化这些变量,即使没有找到记录。明白我的意思了吗?
-
是的,我正在关注你,感谢您的帮助,它正在工作中
标签: php jquery mysql ajax rating-system