Foros del Web » Programación para mayores de 30 ;) » Bases de Datos General » Mysql »

Como hacer esta consulta???

Estas en el tema de Como hacer esta consulta??? en el foro de Mysql en Foros del Web. hola amigos, estoy haciendo un sistema de votacion de fotos y ya tengo el ranking q me muestra los 5 mayormente votados con sus respectivas ...
  #1 (permalink)  
Antiguo 28/07/2010, 16:29
 
Fecha de Ingreso: diciembre-2007
Mensajes: 385
Antigüedad: 16 años, 4 meses
Puntos: 0
Como hacer esta consulta???

hola amigos, estoy haciendo un sistema de votacion de fotos y ya tengo el ranking q me muestra los 5 mayormente votados con sus respectivas fotos, pero lo q necesito agregar ahora es q al q tenga mas votos de los 5 mas votados a ese personaje mostrar su foto mas grande q la de los 4 q lo siguen abajoes decir q al q vaya primero se muestre su foto mas grande q los demas, la consulta q tengo ahora para el ranking es esta:
Código:
SELECT count(votacion.voto) as votos, pinturas.id_pintura, pinturas.pintura_nombre, pinturas.pintura_url, pinturas.mini_pintura_url, artista.id_artista, artista.nombre_artista, artista.colegio_artista, artista.curso_artista FROM artista INNER JOIN pinturas ON pinturas.id_artista= artista.id_artista INNER JOIN votacion ON pinturas.id_pintura= votacion.id_pintura group by pinturas.id_pintura ORDER BY votos DESC LIMIT 5
esa consulta es la q me muestra los 5 mas votados, ahora lo q necesito es q la foto del q va primero en el ranking se muestre mas grande q los 4 q lo siguen. mi code php q por ahora me muestra el ranking de los 5 primeros con su respectiva foto (todas del mismo tamaño) mi code es:
Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php

      $link 
mysql_connect('localhost''root''yo2bik');
 
      if (!
$link)
 
         die(
'Error al conectarse con MySQL: ' mysql_error().' <br>Número del error: '.mysql_errno());
   
         if (! @
mysql_select_db("pintatumundoagathav0.1",$link)){
   
         echo 
"No se pudo conectar correctamente con la Base de datos";
  
         exit();

      }
      
?>
      
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
  <form name="ranking" method="post" action="">
  <?php
  
//CONSULTO PRIMERAS 5 POSICIONES
  
$select_posi="SELECT count(votacion.voto) as votos, pinturas.id_pintura, pinturas.pintura_nombre, pinturas.pintura_url, pinturas.mini_pintura_url, artista.id_artista, artista.nombre_artista, artista.colegio_artista, artista.curso_artista FROM artista INNER JOIN pinturas ON pinturas.id_artista= artista.id_artista INNER JOIN votacion ON pinturas.id_pintura= votacion.id_pintura group by pinturas.id_pintura ORDER BY votos DESC LIMIT 5";

    
$select_posimysql_query($select_posi) or die (mysql_error ());
    
    while(
$row=mysql_fetch_assoc($select_posi))
    {
         echo 
'<center><img src="'.$row["pintura_url"].'"></img></center>';
         echo 
'<center>Nombre: '.$row["nombre_artista"].'</center>';
         echo 
'<center>Curso: '.$row["curso_artista"].'</center>';
         echo 
'<center>Colegio: '.$row["colegio_artista"].'</center>';
         echo 
'<center>Votos: '.$row['votos'].'</center>';
        
// var_dump($row);
    
}

  
  
?>
   <center> <input type="hidden" name="ide_pintura" value="<?php echo $row['ID_PINTURA'];?>"/></center> 
   <br />
  </form>
</body>
</html>
como puedo hacer la consulta para q me muestre al q va primero con la foto mas grande de los 4 q lo siguen o con la consulta sql q tengo actualmente puedo hacer lo q desea solo en php?? si se pudiera como seria??? de antemano gracias...
  #2 (permalink)  
Antiguo 28/07/2010, 16:45
Avatar de masterojitos  
Fecha de Ingreso: julio-2008
Ubicación: Lima Callao Chucuito
Mensajes: 1.931
Antigüedad: 15 años, 9 meses
Puntos: 105
Respuesta: Como hacer esta consulta???

dentro del while, valida si es el primer indice, pones la imagen mas grande y si el indice es mayor a 1, pones de tamaño normal las otras restantes.

Suerte
__________________
Atte. MasterOjitos :ojotes:
Todo sobre Programación Web
Las ultimas tendencias en Efectos y Recursos Web: MasterOjitos Blog
  #3 (permalink)  
Antiguo 28/07/2010, 16:54
 
Fecha de Ingreso: diciembre-2007
Mensajes: 385
Antigüedad: 16 años, 4 meses
Puntos: 0
Respuesta: Como hacer esta consulta???

porfavor me lo podrias ejemplificar en codigo porfa!!!! te lo agradeceria muchisimooo!!!!... de antemano gracias...
  #4 (permalink)  
Antiguo 28/07/2010, 17:03
Avatar de masterojitos  
Fecha de Ingreso: julio-2008
Ubicación: Lima Callao Chucuito
Mensajes: 1.931
Antigüedad: 15 años, 9 meses
Puntos: 105
Respuesta: Como hacer esta consulta???

tu codigo deberia quedar asi

Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php

      $link 
mysql_connect('localhost''root''yo2bik');
 
      if (!
$link)
 
         die(
'Error al conectarse con MySQL: ' mysql_error().' <br>Número del error: '.mysql_errno());
   
         if (! @
mysql_select_db("pintatumundoagathav0.1",$link)){
   
         echo 
"No se pudo conectar correctamente con la Base de datos";
  
         exit();

      }
      
?>
      
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
  <form name="ranking" method="post" action="">
  <?php
  
//CONSULTO PRIMERAS 5 POSICIONES
  
$select_posi="SELECT count(votacion.voto) as votos, pinturas.id_pintura, pinturas.pintura_nombre, pinturas.pintura_url, pinturas.mini_pintura_url, artista.id_artista, artista.nombre_artista, artista.colegio_artista, artista.curso_artista FROM artista INNER JOIN pinturas ON pinturas.id_artista= artista.id_artista INNER JOIN votacion ON pinturas.id_pintura= votacion.id_pintura group by pinturas.id_pintura ORDER BY votos DESC LIMIT 5";

    
$select_posimysql_query($select_posi) or die (mysql_error ());
    
$indice 1;
    while(
$row=mysql_fetch_assoc($select_posi))
    {
        if(
$indice <= 1){
            echo 
'<center><img src="'.$row["pintura_url"].'" width="200" height="200" /></center>'//esta seria la imagen grande
        
}else{
            echo 
'<center><img src="'.$row["pintura_url"].'" width="100" height="100" /></center>'//estas serian laa imagenes normales
        
}
         echo 
'<center>Nombre: '.$row["nombre_artista"].'</center>';
         echo 
'<center>Curso: '.$row["curso_artista"].'</center>';
         echo 
'<center>Colegio: '.$row["colegio_artista"].'</center>';
         echo 
'<center>Votos: '.$row['votos'].'</center>';
        
// var_dump($row);
        
$indice++;
    }
  
  
?>
   <center> <input type="hidden" name="ide_pintura" value="<?php echo $row['ID_PINTURA'];?>"/></center> 
   <br />
  </form>
</body>
</html>
de nada
__________________
Atte. MasterOjitos :ojotes:
Todo sobre Programación Web
Las ultimas tendencias en Efectos y Recursos Web: MasterOjitos Blog
  #5 (permalink)  
Antiguo 28/07/2010, 17:27
 
Fecha de Ingreso: diciembre-2007
Mensajes: 385
Antigüedad: 16 años, 4 meses
Puntos: 0
Respuesta: Como hacer esta consulta???

hola masterojitos, probe como tu me indicaste pero sigue mostrandome todas las imagenes del mismo tamaño te cuento yo en mi BD tengo almacenadas las urls de las imagenes y tengo dos tipos de imagenes, las grandes ylas copias de las imagenes grandes pero en tamaño pequeño y lo hice como tu me dijiste asi:

Código PHP:
$select_posimysql_query($select_posi) or die (mysql_error ());
    
$indice 1;
    
    while(
$row=mysql_fetch_assoc($select_posi))
    {
        if(
$indice <= 1)
        {
            echo 
$indice;
         echo 
'<center><img src="'.$row["pintura_url"].'"></img></center>';
         }else{
             
         echo 
'<center><img src="'.$row["mini_pintura_url"].'"></img></center>';
               }
         echo 
'<center>Nombre: '.$row["nombre_artista"].'</center>';
         echo 
'<center>Curso: '.$row["curso_artista"].'</center>';
         echo 
'<center>Colegio: '.$row["colegio_artista"].'</center>';
         echo 
'<center>Votos: '.$row['votos'].'</center>'
pero sigue mostrandome todas las imagenes del mismo tamaño es decir grandes, ademas la variable indice no me imprime nada, como lo puedo hacer o en q estoy fallando??? agradeceria mucho nuevamente tu ayuda de antemano gracias.
  #6 (permalink)  
Antiguo 28/07/2010, 17:57
Avatar de masterojitos  
Fecha de Ingreso: julio-2008
Ubicación: Lima Callao Chucuito
Mensajes: 1.931
Antigüedad: 15 años, 9 meses
Puntos: 105
Respuesta: Como hacer esta consulta???

yo puse esto:

Código PHP:
Ver original
  1. <?php
  2.   //CONSULTO PRIMERAS 5 POSICIONES
  3.   $select_posi="SELECT count(votacion.voto) as votos, pinturas.id_pintura, pinturas.pintura_nombre, pinturas.pintura_url, pinturas.mini_pintura_url, artista.id_artista, artista.nombre_artista, artista.colegio_artista, artista.curso_artista FROM artista INNER JOIN pinturas ON pinturas.id_artista= artista.id_artista INNER JOIN votacion ON pinturas.id_pintura= votacion.id_pintura group by pinturas.id_pintura ORDER BY votos DESC LIMIT 5";
  4.  
  5.     $select_posi= mysql_query($select_posi) or die (mysql_error ());
  6.     $indice = 1;
  7.     while($row=mysql_fetch_assoc($select_posi))
  8.     {
  9.          echo '<center>Indice: '.$indice.'</center>'; //esto es solo de prueba
  10.         if($indice <= 1){
  11.             echo '<center><img src="'.$row["pintura_url"].'" width="200" height="200" /></center>'; //esta seria la imagen grande
  12.         }else{
  13.             echo '<center><img src="'.$row["pintura_url"].'" width="100" height="100" /></center>'; //estas serian laa imagenes normales
  14.         }
  15.          echo '<center>Nombre: '.$row["nombre_artista"].'</center>';
  16.          echo '<center>Curso: '.$row["curso_artista"].'</center>';
  17.          echo '<center>Colegio: '.$row["colegio_artista"].'</center>';
  18.          echo '<center>Votos: '.$row['votos'].'</center>';
  19.         // var_dump($row);
  20.         $indice++;
  21.     }
  22.  
  23.   ?>

Prueba y me comentas...

suerte:
__________________
Atte. MasterOjitos :ojotes:
Todo sobre Programación Web
Las ultimas tendencias en Efectos y Recursos Web: MasterOjitos Blog
  #7 (permalink)  
Antiguo 29/07/2010, 06:13
 
Fecha de Ingreso: diciembre-2007
Mensajes: 385
Antigüedad: 16 años, 4 meses
Puntos: 0
Respuesta: Como hacer esta consulta???

muchas gracias masterojitos, ahora si resulto, sorry por la demora de mi respuesta es q anoche me iba a mi casa ya desde el trabajo, gracias nuevamente ... cualquier csa vuelvo a postear muchas gracias ....slds

Etiquetas: Ninguno
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 20:56.