Ver Mensaje Individual
  #1 (permalink)  
Antiguo 30/05/2009, 21:50
Avatar de EmaD
EmaD
 
Fecha de Ingreso: marzo-2008
Mensajes: 93
Antigüedad: 16 años, 1 mes
Puntos: 2
Como optimizar consulta con randon

gente la cuestione s asi , tengo un script en mi web qeu hice hace unos dias , que devuelve mediante una consulta un video entre unos 250 que hay en la base de datos de mi web.

la consulta es esta.

Código:
SELECT id,title,id_author FROM videos
                    ORDER BY RAND() LIMIT 0, 1
Como puedo hacer para optimizarla , por lo que lei no es la mejor forma de hacerlo.

Estee s el codigo qeu uso para mostrarla en un bloque de mi web en php.

Código PHP:

        
        
<?php
error_reporting
(0);
class 
videos_randon
    
{
     var 
$content;
    
    function 
videos_randon()
        {
        global 
$website

    
$this->content='<h1>Tu Video</h1>'
        
$this->content.='<div class="block_content"><p>';
        
//aca la consulta con el RAND()

 
$result mysql_query("SELECT id,title,id_author FROM videos
                    ORDER BY RAND() LIMIT 0, 1"
);
           

                
           
$data mysql_fetch_array($result);
                            
                    
$title=remove_html(cut($data['title'],100));
                    
$title2=remove_html($data['title']);
                    
$paraenlace GetQuitarAcentos($title2);
                    
                    
$this->content.="    <center>                

<a href=\"VIDEO-"
.$data['id']."-".$paraenlace.".htm\" onMouseOver=\"return overlib('".$title2."', CAPTION, 'Tu Video Aleatorio')\" onMouseOut=\"return nd();\">";
                                
                    
$this->content.= $title.'';
                    
$this->content.= '<br><img src="images/rvideo.jpg">';

                    
$this->content.= '</a></center>';
                        
        
         
$this->content.="</p></div>";
        
         
         
         
        }
        
        function 
display()
        {
        return 
$this->content;
        }    
        
        }
        
?>
Salu2 y gracias por su tiempo