2010-01-21 15 views
14

मुझे निम्न त्रुटि मिल रही है और मैं सोच रहा था कि कैसे ठीक किया जाए?PHP - घातक त्रुटि: असमर्थित ऑपरेंड प्रकार

यह दूसरी बार है जब मुझे यह त्रुटि मिली, मैंने इसे पहली बार तय किया लेकिन किसी कारण से मैं इसे दूसरी बार ठीक नहीं कर सकता।

Fatal error: Unsupported operand types on line 103 

यहाँ यहाँ लाइन 103.

$avg = (round($total_rating_points/$total_ratings,1)); 

है पूरा कोड के नीचे है।

function getRatingText(){ 
    $dbc = mysqli_connect ("localhost", "root", "", "sitename"); 

    $page = '3'; 

    $sql1 = "SELECT COUNT(users_articles_id) 
      FROM articles_grades 
      WHERE users_articles_id = '$page'"; 

    $result = mysqli_query($dbc,$sql1); 

    if (!mysqli_query($dbc, $sql1)) { 
      print mysqli_error($dbc); 
      return; 
    } 

    $total_ratings = mysqli_fetch_array($result); 

    $sql2 = "SELECT grade_points 
      FROM grades 
      JOIN articles_grades ON grades.id = articles_grades.grade_id 
      WHERE articles_grades.users_articles_id = '$page'"; 

    $result = mysqli_query($dbc, $sql2); 

    if (!mysqli_query($dbc, $sql2)) { 
      print mysqli_error($dbc); 
      return; 
    } 

    while($row = mysqli_fetch_array($result)) { 

     $trp[] = $row[0]; 
    } 

    $total_rating_points = array_sum($trp); 

    if (!empty($total_rating_points) && !empty($total_ratings)){ 
     $avg = (round($total_rating_points/$total_ratings,1)); 
     $votes = $total_ratings; 
     echo $avg . "/10 (" . $votes . " votes cast)"; 
    } else { 
     echo '(no votes cast)'; 
    } 
} 
+0

मुझे लगता है कि मैंने इसे हल किया है सबको धन्यवाद! – tEcHnUt

+6

अपने पिछले खाते में पासवर्ड भूल गए? http://stackoverflow.com/questions/2077618/php-fatal-error-unsupported-operand-types और http://stackoverflow.com/users/252134/technut देखें – VolkerK

उत्तर

41

$total_ratings एक सरणी है, जिसे आप किसी विभाजन के लिए उपयोग नहीं कर सकते हैं।

ऊपर से:

$total_ratings = mysqli_fetch_array($result); 
0

मुझे लगता है कि आप ऐसा करना चाहते हैं:

$total_rating_count = count($total_rating_count); 
if ($total_rating_count > 0) // because you can't divide through zero 
    $avg = round($total_rating_points/$total_rating_count, 1); 
2

मैं निम्नलिखित कोड के साथ एक समान त्रुटि थी: -

foreach($myvar as $key => $value){ 
    $query = "SELECT stuff 
      FROM table 
      WHERE col1 = '$criteria1' 
      AND col2 = '$criteria2'"; 

    $result = mysql_query($query) or die('Could not execute query - '.mysql_error(). __FILE__. __LINE__. $query);    
    $point_values = mysql_fetch_assoc($result); 
    $top_five_actions[$key] += $point_values; //<--- Problem Line  
} 

यह पता चला कि मेरी $ point_values ​​चर कभी कभी झूठी लौट रहा था जो समस्या का कारण बन गया, इसलिए मैंने इसे mysql_num_rows में लपेटकर तय किया: -

if(mysql_num_rows($result) > 0) { 
     $point_values = mysql_fetch_assoc($result); 
     $top_five_actions[$key] += $point_values; 
} 

नहीं यकीन है कि यह मदद करता है हालांकि?

चीयर्स

संबंधित मुद्दे