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 我想在一个软件里添加一个优惠弹窗,应该怎么写代码
  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流