Visualizzazione dei risultati da 1 a 7 su 7

Discussione: Query da risolvere

Hybrid View

  1. #1
    facci sapere come, così aiuti qualche altro forumista che dovesse avere il tuo stesso problema

  2. #2
    Quote Originariamente inviata da optime Visualizza il messaggio
    facci sapere come, così aiuti qualche altro forumista che dovesse avere il tuo stesso problema
    <table style="border: 1px solid black;">
    <tr bgcolor="YELLOW">

    <th> POSIZIONE</th>
    <th> COGNOME </th>
    <th> NOME </th>
    <th> PUNTI PARTITA </th>
    </tr>


    <?php
    $tornei = $_POST['tornei'];
    $lega = $_POST['lega'];

    $table = array();

    if(isset($tornei)){

    //trovo i players appartenenti a quel torneo in quella lega
    $sqlpl = "SELECT DISTINCT cognome, nome, Players.id_pl as playerId FROM Players, Partecipa_pl_to, Tornei, Partite, Tavoli, Gioca_pl_ta,
    App_le_to,Leghe
    WHERE Players.id_pl = Partecipa_pl_to.id_pl AND Partecipa_pl_to.id_torneo = Tornei.nome_torneo
    AND Tornei.nome_torneo = Partite.nome_torneo AND Tavoli.id_partita = Partite.id_partita
    AND Tavoli.id_tavolo = Gioca_pl_ta.id_tavolo AND Gioca_pl_ta.id_pl = Players.id_pl AND
    Tornei.nome_torneo = App_le_to.nome_torneo AND App_le_to.nome_lega = Leghe.nome_lega
    AND Tornei.nome_torneo = '$tornei' AND Leghe.nome_lega ='$lega' ORDER BY cognome;";

    $resultpl = mysqli_query($conn, $sqlpl);


    while ($rowpl = $resultpl->fetch_assoc()){
    $cognome = $rowpl['cognome'];
    $nome = $rowpl['nome'];
    $playerId = $rowpl['playerId'];

    //trovo i 4 punteggi migliori di quel player
    $sqltopu = "SELECTSUM(punti_partita) as punti_partita FROM Players, Partecipa_pl_to, Tornei, Partite, Tavoli, Gioca_pl_ta,
    App_le_to, Leghe WHERE Players.id_pl = Partecipa_pl_to.id_pl AND Partecipa_pl_to.id_torneo = Tornei.nome_torneo
    AND Tornei.nome_torneo = Partite.nome_torneo AND Tavoli.id_partita = Partite.id_partita
    AND Tavoli.id_tavolo = Gioca_pl_ta.id_tavolo AND Gioca_pl_ta.id_pl = Players.id_pl AND
    Tornei.nome_torneo = App_le_to.nome_torneo AND App_le_to.nome_lega = Leghe.nome_lega
    AND Tornei.nome_torneo = '$tornei' AND Leghe.nome_lega ='$lega' AND Players.id_pl='$playerId'
    ORDER BY punti_partita DESCLIMIT4";

    $resultpu = mysqli_query($conn, $sqltopu);
    //variabile sommapunti

    while ($rowtopu = $resultpu->fetch_assoc()){
    $row = array(
    "punti" => (int) $rowtopu["punti_partita"],
    "nome" => $nome,
    "cognome" => $cognome
    );
    $table[] = $row;
    } //chiusura secondo while

    } // chiusura primo while

    usort($table, function ($item1, $item2) {
    return $item2['punti'] <=> $item1['punti'];
    });
    $i=1;
    foreach ($table as $key => $value) {
    ?>
    <tr>
    <td><?php echo "".$i ?></td-->
    <td><?php echo($value["nome"]) ?></td>
    <td><?php echo($value["cognome"]) ?></td>
    <td><?php echo($value["punti"]) ?></td>
    </tr>
    <?php
    $i++;
    }
    ?>

    </table>

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.