Ver Mensaje Individual
  #1 (permalink)  
Antiguo 15/12/2004, 12:07
Avatar de Reynier
Reynier
 
Fecha de Ingreso: noviembre-2002
Ubicación: Por ahí en algún sitio
Mensajes: 1.844
Antigüedad: 24 años
Puntos: 1
Optimizar consulta

Hola:
Estoy realizando un sistema de estadísticas y ya he logrado que funcione a la perfección, bueno ???. Ahora tengo esto:
Código PHP:
  $sowin = "SELECT COUNT(ipusuario) AS totalwin FROM estadisticas WHERE (sistemaoperativo=1)";
  
$reswin = mysql_query($sowin) or die(_DBERR);
  
$fetchwin = mysql_fetch_array($reswin);
  
$porcientowin = (100*$fetchwin['totalwin'])/$total;
  
$somac = "SELECT COUNT(ipusuario) AS totalmac FROM estadisticas WHERE (sistemaoperativo=2)";
  
$resmac = mysql_query($somac) or die(_DBERR);
  
$fetchmac = mysql_fetch_array($resmac);
  
$porcientomac = (100*$fetchmac['totalmac'])/$total;
  
$solin = "SELECT COUNT(ipusuario) AS totallin FROM estadisticas WHERE (sistemaoperativo=3)";
  
$reslin = mysql_query($solin) or die(_DBERR);
  
$fetchlin = mysql_fetch_array($reslin);
  
$porcientolin = (100*$fetchlin['totallin'])/$total;
  
$sobsd = "SELECT COUNT(ipusuario) AS totalbsd FROM estadisticas WHERE (sistemaoperativo=4)";
  
$resbsd = mysql_query($sobsd) or die(_DBERR);
  
$fetchbsd = mysql_fetch_array($resbsd);
  
$porcientobsd = (100*$fetchbsd['totalbsd'])/$total;
  
$sosun = "SELECT COUNT(ipusuario) AS totalsun FROM estadisticas WHERE (sistemaoperativo=5)";
  
$ressun = mysql_query($sosun) or die(_DBERR);
  
$fetchsun = mysql_fetch_array($ressun);
  
$porcientosun = (100*$fetchsun['totalsun'])/$total;
  
$soiri = "SELECT COUNT(ipusuario) AS totaliri FROM estadisticas WHERE (sistemaoperativo=6)";
  
$resiri = mysql_query($soiri) or die(_DBERR);
  
$fetchiri = mysql_fetch_array($resiri);
  
$porcientoiri = (100*$fetchiri['totaliri'])/$total;
  
$sobeo = "SELECT COUNT(ipusuario) AS totalbeo FROM estadisticas WHERE (sistemaoperativo=7)";
  
$resbeo = mysql_query($sobeo) or die(_DBERR);
  
$fetchbeo = mysql_fetch_array($resbeo);
  
$porcientobeo = (100*$fetchbeo['totalbeo'])/$total;
  
$soos2 = "SELECT COUNT(ipusuario) AS totalos2 FROM estadisticas WHERE (sistemaoperativo=8)";
  
$resos2 = mysql_query($soos2) or die(_DBERR);
  
$fetchos2 = mysql_fetch_array($resos2);
  
$porcientoos2 = (100*$fetchos2['totalos2'])/$total;
  
$soaix = "SELECT COUNT(ipusuario) AS totalaix FROM estadisticas WHERE (sistemaoperativo=9)";
  
$resaix = mysql_query($soaix) or die(_DBERR);
  
$fetchaix = mysql_fetch_array($resaix);
  
$porcientoaix = (100*$fetchaix['totalaix'])/$total;

  
$navope = "SELECT COUNT(ipusuario) AS totalope FROM estadisticas WHERE (navegador=1)";
  
$resnav = mysql_query($navope) or die(_DBERR);
  
$fetchope = mysql_fetch_array($resnav);
  
$porcientoope = (100*$fetchope['totalope'])/$total;
  
$naviex = "SELECT COUNT(ipusuario) AS totaliex FROM estadisticas WHERE (navegador=2)";
  
$resnav = mysql_query($naviex) or die(_DBERR);
  
$fetchiex = mysql_fetch_array($resnav);
  
$porcientoiex = (100*$fetchiex['totaliex'])/$total;
  
$navlyn = "SELECT COUNT(ipusuario) AS totallyn FROM estadisticas WHERE (navegador=3)";
  
$resnav = mysql_query($navlyn) or die(_DBERR);
  
$fetchlyn = mysql_fetch_array($resnav);
  
$porcientolyn = (100*$fetchlyn['totallyn'])/$total;
  
$navwtv = "SELECT COUNT(ipusuario) AS totalwtv FROM estadisticas WHERE (navegador=4)";
  
$resnav = mysql_query($navwtv) or die(_DBERR);
  
$fetchwtv = mysql_fetch_array($resnav);
  
$porcientowtv = (100*$fetchwtv['totalwtv'])/$total;
  
$navkon = "SELECT COUNT(ipusuario) AS totalkon FROM estadisticas WHERE (navegador=5)";
  
$resnav = mysql_query($navkon) or die(_DBERR);
  
$fetchkon = mysql_fetch_array($resnav);
  
$porcientokon = (100*$fetchkon['totalkon'])/$total;
  
$navmoz = "SELECT COUNT(ipusuario) AS totalmoz FROM estadisticas WHERE (navegador=6)";
  
$resnav = mysql_query($navmoz) or die(_DBERR);
  
$fetchmoz = mysql_fetch_array($resnav);
  
$porcientomoz = (100*$fetchmoz['totalmoz'])/$total;
  
$navnet = "SELECT COUNT(ipusuario) AS totalnet FROM estadisticas WHERE (navegador=7)";
  
$resnav = mysql_query($navnet) or die(_DBERR);
  
$fetchnet = mysql_fetch_array($resnav);
  
$porcientonet = (100*$fetchnet['totalnet'])/$total;
  
$navotr = "SELECT COUNT(ipusuario) AS totalotr FROM estadisticas WHERE (navegador=8)";
  
$resnav = mysql_query($navotr) or die(_DBERR);
  
$fetchotr = mysql_fetch_array($resnav);
  
$porcientootr = (100*$fetchotr['totalotr'])/$total; 
y lo que quiero hacer es optimizar un poco ese código para hacer más legible y pequeñas las cosas.

Salu2
__________________
Ing. Reynier Pérez Mira