php - Trouble performing calculations on MySQL result sets -
i trying calculate percentage of votes each record. each record coming out 100 percent despite each record having different number of votes. why happening?
$artistname = "select * voting"; $artistnameresults = mysql_query( $artistname ) or die( "could not video games " .mysql_error() );  for( $i = 0; $i < mysql_numrows( $artistnameresults ); $i++ ) {     $data = mysql_fetch_array( $artistnameresults );      echo "<div>". $data['artist'] ." has " . $data['votes'] ." votes ";      if($total_votes > 0)         $temp_votes = $data['votes']/$total_votes;     else         $temp_votes = 1;      echo '( '.($temp_votes*100).'%)';     echo "</div>\n"; }      
you dont have in $total_votes..
$total_votes = $data['whatever_total_votes_is_here']; if($total_votes > 0)         $temp_votes = $data['votes']/$total_votes;     else         $temp_votes = 1;   if don't have count of total votes in $data have count or length figure out number.
pass total_votes can check on it
Comments
Post a Comment