我之前使用过相同的代码而不是那样只是一次只有一个图像它在那里工作正常显示img(星星)但是现在第一个值的星星很好接下来它正在收集前一个的结果
while ($query = mysql_fetch_array($tableone))
{
$Rating = $query['rating'];
$totalV = $query['total_votes'];
$commentcount = $query['comment_counts'];
if (!$Rating == 0 )
{
$number = $Rating / $totalV ;
$numbers = (round($number,3));
for ($x = 1 ; $x <= $numbers ; $x++)
{
$star .= '<img src="img/stars.gif" width="14%"/>';
}
$left = 5 - $numbers ;
for ($x = 1 ; $x <= $left ; $x++)
{
$result .='<img src="img/whitestar.gif" width="12%"/>';
}
if ( strpos($left, '.' ) == true)
{
$hs .= '<img src="img/halfwhitestar.gif" width="12%"/>';
}
$result1 = $star. $hs .$result;
}
else
{
$result1 ='Null';
}
if (empty($totalV))
{
$totalV = 'No votes';
}
$totalV ="/".$totalV;
$ratingbox = "<span id=\"ratingimg\">".$result1." </span>
<br/>
<span class=\"valueimg\">".$number.$totalV."</span>";
}
我在每个图像的数据库中的值是
并且此代码可以像这样显示
此代码我现在用于数据库中存在的所有图像的表格,包括它们的一些信息......需要指导:S
答案 0 :(得分:1)
由于您在循环期间连接字符串,因此每次迭代循环时这些字符串都会不断增长。
我建议您在while
循环的每次迭代时将这些变量重置为空字符串:$star
,$hs
,$result
。
这样的事情:
while ($query = mysql_fetch_array($tableone)) {
$star=$hs=$result='';
...