title: help with a query
body: <p>i have a function where i get the ratings of the selected user by id, 
  it gets the ratings from one type of things, the ratings of a diff type of things and then does a+b</p>
  
  <p>i know it's not very optimized but i'm focus on making all work...</p>
  
  <p>this i do it like this</p>
  
  <pre><code>    function votos_usuario($id){
  
              $previa = "SELECT id FROM preguntas WHERE id_usuario = '$id'";
              $r_previo = mysql_query($previa);
              $ids_p = '0, ';
              while($items_previos = mysql_fetch_array($r_previo)){
                  $ids_p .= $items_previos['id'].", ";
                  //echo "ids pregunta usuario: ".$items_previos['id']."&lt;br&gt;";
              }
              $ids = substr($ids_p,0,-2);
              //echo $ids;
  
              $consulta = "SELECT valor FROM votos_pregunta WHERE id_pregunta IN ( $ids )";
              //echo $consulta;
  
             $resultado = mysql_query($consulta);
             $votos_preguntas = 0;
             while($voto = mysql_fetch_array($resultado)){
               $votos_preguntas = $votos_preguntas + $voto['valor'];
             }
  //$votos_preguntas= 0;
  //$votos_preguntas = mysql_query("SELECT SUM(valor) FROM votos_pregunta WHERE id_pregunta IN (SELECT id FROM preguntas WHERE id_usuario = '$id')");
  
  
             $previa_r = "SELECT id FROM recetas WHERE id_usuario = '$id'";
              $r_previo_r = mysql_query($previa_r);
              $ids_r = '0, ';
              while($items_previos_r = mysql_fetch_array($r_previo_r)){
                  $ids_r .= $items_previos_r['id'].", ";
                  //echo "ids pregunta usuario: ".$items_previos['id']."&lt;br&gt;";
              }
              $ids = substr($ids_r,0,-2);
              $consulta_b = "SELECT valor FROM votos_receta WHERE id_receta IN ( $ids )";
              //echo $consulta;
  
             $resultado_b = mysql_query($consulta_b);
             $votos_recetas = 0;
             while($voto_r = mysql_fetch_array($resultado_b)){
               $votos_recetas = $votos_recetas + $voto_r['valor'];
             }
  
  
  
  
  
              $total = $votos_preguntas + $votos_recetas;
              return $total;
  
          }
  </code></pre>
  
  <p>Now the Question,</p>
  
  <p>how can i do it to get all users ordered by rating desc ???? i just can't see it :S</p>