douyanyan1123 2014-04-21 23:53
浏览 58
已采纳

mysql_fetch_array包含下一个的前一个值

I used this same code before and not like that just for one image at one time it is working fine there for showing img(stars)but now stars in first value is fine next it is collecting result with previous one

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>";

}

my Values in database of each image is

rating and total votes in database

and this code is visible like this

rating par Image it is including previous values as well in next

this code i am using now for table for all images present in database including their some information...need guidance:S

  • 写回答

1条回答 默认 最新

  • douhu2525 2014-04-22 00:09
    关注

    Since you are concatenating strings during your loop, those strings just keep growing with each iteration of the loop.

    I suggest that you reset these variables to blank strings upon each iteration of your while loop: $star, $hs, $result.

    Something like this:

    while ($query = mysql_fetch_array($tableone)) {
    
        $star=$hs=$result='';
    
        ...
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用verilog实现tanh函数和softplus函数
  • ¥15 求京东批量付款能替代天诚
  • ¥15 slaris 系统断电后,重新开机后一直自动重启
  • ¥15 51寻迹小车定点寻迹
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题