Page 1 of 1
% from a database
Posted: Tue Oct 29, 2002 11:32 am
by m3mn0n
Say i save 3500 survey results in a database, they include the choices of the survey and the things the visitors picked. Counting the number of total entries in the database is easy, but how would extract a percentage from the survey results? Maybe it's because i had a long nite, but i just can't figure this one out or find a tutorial on this topic.
thanks~
Posted: Tue Oct 29, 2002 3:28 pm
by volka
Code: Select all
$query = 'SELECT count(*) from tablename';
$result = mysql_query($query, $conn);
$totalnum = mysql_fetch_row($result);
$totalnum = $totalnumї0];
$query = 'SELECT rating,count(*) from tablename group by rating';
$result = mysql_query($query, $conn);
while( $row = mysql_fetch_row($result) )
echo $rowї0], ' voted ', $rowї1], ' times (', $rowї1]*100/$totalnum, '%)';