简体   繁体   中英

mysql_fetch_array is including previous value in next one

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

数据库中的评分和总票数

and this code is visible like this

评级par图像,它也包括下一个值

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

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='';

    ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM