2014-04-21 19 views
0

我以前使用過這個相同的代碼,而不是像這樣只是一個圖像一次它工作正常顯示img(星星),但現在星星在第一個值罰款下一個它是與前一個mysql_fetch_array包括之前的值在下一個

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

} 

我在每幅圖像的數據庫中收集的值結果是

rating and total votes in database

這個代碼是這樣的

可見

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

這個代碼我現在使用的表,包括他們的一些資料...需要指導存在於數據庫中的所有圖片:S

回答

1

因爲你是你的循環過程中連接字符串,這些字符串只是保持增長循環的每次迭代。

我建議你在你的while每次循環重置這些變量爲空字符串:$star$hs$result

事情是這樣的:

while ($query = mysql_fetch_array($tableone)) { 

    $star=$hs=$result=''; 

    ...