Tengo una BD Mysql en donde se guardan los resultados de una encuesta, cada pregunta tiene de 5 hasta 14 opciones de respuesta.
El conteo lo estoy haciendo asi :
Código PHP:
$conexion=mysql_connect("xyz","xyz","xyz") or
die("Problemas en la conexion");
mysql_select_db("xyz",$conexion) or
die("Problemas en la selección de la base de datos");
Código PHP:
//para la pregunta 1 y opcion de respuesta 1
$registros=mysql_query("SELECT count(p1) as total1 FROM xyz where p1='r1';",$conexion) or
die("Problemas en el select:".mysql_error());
$reg=mysql_fetch_array($registros);
$total1=$reg['total1'];
echo $total1;
//para la pregunta 1 y opcion de respuesta 2
$registros=mysql_query("SELECT count(p1) as total2 FROM xyz where p1='r2';",$conexion) or
die("Problemas en el select:".mysql_error());
$reg=mysql_fetch_array($registros);
$total2=$reg['total2'];
echo $total2;
//y asi sucesivamente hasta mostrar un total al final
$totalp1=$total1+$total2+$total3+$total4+$total5;
echo $totalp1;