Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2004
    Location
    Brasil
    Posts
    247

    php mysql query help

    I have a TABLE like this:
    Code:
       rid  login  pos  pnt  rank  
          1001 Paulo 1 55,20 Domingo 
          1001 Pablao 2 45,60 Domingo 
          1001 Head_Neck 3 36,00 Domingo 
          1001 Panstro 4 28,80 Domingo 
          1001 MUSH_PILLS 5 21,60 Domingo 
          1001 Romulo 6 16,80 Domingo 
          1001 Yo 7 12,00 Domingo 
          1001 Henry 8 9,60 Domingo 
          1001 Rodrigao 9 7,20 Domingo 
          1001 Luciano 10 7,20 Domingo 
          1001 Ximbao 11 0,00 Domingo 
          1001 George 12 0,00 Domingo 
          1002 Levy 1 73,60 Segunda 
          1002 Belo 2 60,80 Segunda 
          1002 Rodrigao 3 48,00 Segunda 
          1002 Alex_CTBA 4 38,40 Segunda 
          1002 Chimbica 5 28,80 Segunda 
          1002 PEXERO 6 22,40 Segunda 
          1002 RM 7 16,00 Segunda 
          1002 Rodrigo_CTBA 8 12,80 Segunda 
          1002 Head_Neck 9 9,60 Segunda 
          1002 MUSH_PILLS 10 9,60 Segunda 
          1002 Yo 11 0,00 Segunda 
          1002 Ximbao 12 0,00 Segunda 
          1002 M.Fagundes 13 0,00 Segunda 
          1002 Malvezzi 14 0,00 Segunda 
          1002 Pablao 15 0,00 Segunda 
          1002 George 16 0,00 Segunda
    i want to filter the RANK collum and pick DISTINT login. Ok
    i want that every login plus their points. Ok
    i want to ORDER that in ASC, like more to less. Dont work now because if i put more results on table, the ORDER will be from first MYSQL query.

    CODE:
    Code:
    function verrank($rankde){
    if($rankde=="Segunda"){
    
    $SEGa = "SELECT DISTINCT `login` FROM `pontos` WHERE `rank` LIKE 'Segunda'";
    $rSEGa = @mysql_query($SEGa) or error("Erro no SQL Seg!");
    //$ddra = mysql_fetch_array($rSEGa);
    
    while($ddra = mysql_fetch_array($rSEGa)){
    $llg = $ddra["login"];
    $SEGb = mysql_query("SELECT * FROM pontos WHERE rank='Segunda' AND login='$llg'");
    $pontos = 0;
    $jogou = mysql_num_rows($SEGb);
    	while($rSEGb = mysql_fetch_array($SEGb)){
    	$pontos = $pontos+$rSEGb["pnt"];
    	}
    $mpnt = $pontos / $jogou;
    echo"$SEGb -> $llg jogou $jogou jogos. Fez um total de $pontos. Com média de $mpnt<br>";
    }
    
    }
    
    }
    SITE:
    http://www.pokerjoinville.com.br/?op...rankde=Segunda

    Thanks!
    "Only two things are infinite, the universe and human stupidity, and I'm not sure about the former" Albert Einstein

  2. #2
    Join Date
    Feb 2005
    Location
    Australia
    Posts
    5,842
    If you just want to sort the results then add "ORDER BY login" to the first query.

    But it looks like what you really want is a GROUP BY query, something like (untested):
    Code:
    SELECT `login`, COUNT(*) AS jogou, SUM(`pnt`) AS total_pontos
    FROM `pontos`
    WHERE `rank` LIKE 'Segunda'
    GROUP BY `login`
    http://dev.mysql.com/doc/refman/4.1/...functions.html
    Chris

    "Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter

  3. #3
    Join Date
    Oct 2004
    Location
    Brasil
    Posts
    247
    Thank YOU!

    I ll never find a solution to this.

    Now is:
    Code:
    function verrank($rankde){
    if($rankde=="Segunda"){
    
    $SEGa = "SELECT *, COUNT(`login`) AS jogou, SUM(`pnt`) AS total_pontos FROM `pontos` WHERE `rank` LIKE 'Segunda' GROUP BY `login` ORDER BY total_pontos DESC";
    $rSEGa = @mysql_query($SEGa) or error("Erro no SQL Seg!");
    
    while($ddra = mysql_fetch_array($rSEGa)){
    $llg = $ddra["login"];
    $pnts = $ddra["total_pontos"];
    $jogos = $ddra["jogou"];
    $media =$pnts / $jogos;
    echo"$llg jogou $jogos jogos. Fez um total de $pnts. Com média de $media<br>";
    }
    
    }
    }
    I just put and order by!

    Thanks at all!!

    Regards
    "Only two things are infinite, the universe and human stupidity, and I'm not sure about the former" Albert Einstein

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •