Slight Help on query needed

Discussion in 'PHP' started by Basti, Nov 14, 2010.

  1. #1
    So ive made a query to calculate a rank for my pages, which is working great. Now however i would like to take in another rank calculation factor.

    Currently it only take in average and number of votes ( from which i calculate a number to later output the rank )

    
    $value_max = 5;
    
    $result = mysql_query("SELECT content_id, ROUND(ROUND(AVG(value) * '{$value_max}' / 100, 4) * (COUNT(content_id) / 100), 4) + '{$num_loved}' AS average FROM votingapi_vote GROUP BY content_id ORDER BY average DESC") or die(mysql_error());
    
    $rank = 1;
    
    while($row = mysql_fetch_array($result))
    {
     if($row['content_id'] == $nid) {
        
        $movie_rank = $rank;
     }
      $rank++;
    }
    
    PHP:
    The $num_loved is the new factor i wanna take in ( people who loved this page, simple as 1,2,3 or 4 etc ) Taken by mysql_num_rows from a previous query
    Now when i change
    
        $movie_rank = $rank;
    
    Code (markup):
    to
    
        $movie_rank = $row['average'];
    
    Code (markup):
    the actual number increases for example from 6.55 to 11.55 which is exactly what i need.

    Now the actual problem:
    when i switch back to $rank the movie still got its old rank, while it actually should grow 1 rank higher.

    Anyone got an idea why? I am totally struck :(
    Thanks for any tips, help
     
    Basti, Nov 14, 2010 IP
  2. Basti

    Basti Active Member

    Messages:
    625
    Likes Received:
    6
    Best Answers:
    3
    Trophy Points:
    90
    #2
    Does nobody have an idea why it dont recognize num_loved in the rank++ ??
     
    Basti, Nov 16, 2010 IP