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

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -