Visualizzazione dei risultati da 1 a 3 su 3

Discussione: impaginare pagina php

  1. #1
    Utente di HTML.it
    Registrato dal
    Oct 2004
    Messaggi
    138

    impaginare pagina php

    Salve a tutti, nel mio blog della squadra di calcetto (piattaforma wordpress) ho fatto una sezione di statistiche in php che creano varie tabelle come classifica cannonieri, classifica portieri etc...

    il codice per le query è il seguente:

    Codice PHP:
    <?php

    $db 
    mysqli_connect(''******, '*******''********');
    if( !
    $db|| mysqli_connect_errno() == true ) { 
        die( 
    "Errore durante la connessione: ".mysqli_connect_error() ); 
    }
    else {
        
    $db->select_db'ssscaten_db' );


    $result$db->query'SELECT Nome_Cognome, Count(*) FROM Giocatore g inner join PresenzePartita pp on g.Id_Giocatore=pp.Id_Giocatore  where pp.Id_Stagione=2 GROUP BY Nome_Cognome order by Count(*) DESC') or die( $db->error );

    echo 
    "<table>";
    echo 
    "<tbody><tr><th>Giocatore</th><th>Presenze</th>";
    if (
    $result->num_rows != 0)
              {while(
    $Presenze$result->fetch_assoc()) 
    {

    $Presenze"</tr>
    <tr>
    <td>"
    .$Presenze['Nome_Cognome']."</td>
    <td>"
    .$Presenze['Count(*)']."</td>
    </tr>"
    ;
    echo 
    $Presenze;

    }}
    echo 
    "</tbody></table>";

    $result$db->query'SELECT Nome_Cognome, sum(pp.Goal_Fatti) FROM Giocatore g inner join PresenzePartita pp on g.Id_Giocatore=pp.Id_Giocatore  where pp.Id_Stagione=2 GROUP BY Nome_Cognome order by sum(pp.Goal_Fatti) DESC') or die( $db->error );

    echo 
    "<table>";
    echo 
    "<tbody><tr><th>Giocatore</th><th>Goal Fatti</th>";
    if (
    $result->num_rows != 0)
              {while(
    $Marcatori$result->fetch_assoc()) 
    {

    $Marcatori"</tr>
    <tr>
    <td>"
    .$Marcatori['Nome_Cognome']."</td>
    <td>"
    .$Marcatori['sum(pp.Goal_Fatti)']."</td>
    </tr>"
    ;
    echo 
    $Marcatori;

    }}
    echo 
    "</tbody></table>";

    $porti$db->query'SELECT Nome_Cognome, sum(pp.Goal_Subiti) FROM Giocatore g inner join PresenzePartita pp on g.Id_Giocatore=pp.Id_Giocatore  where pp.Id_Stagione=2 GROUP BY Nome_Cognome order by sum(pp.Goal_Subiti) DESC') or die( $db->error );

    echo 
    "<table>";
    echo 
    "<tbody><tr><th>Giocatore</th><th>Goal Subiti</th>";
    if (
    $porti->num_rows != 0)
              {while(
    $Portieri$porti->fetch_assoc()) 
    {

    $Portieri"</tr>
    <tr>
    <td>"
    .$Portieri['Nome_Cognome']."</td>
    <td>"
    .$Portieri['sum(pp.Goal_Subiti)']."</td>
    </tr>"
    ;
    echo 
    $Portieri;

    }}
    echo 
    "</tbody></table>";

    $result$db->query'SELECT Nome_Cognome, sum(pp.Assist) FROM Giocatore g inner join PresenzePartita pp on g.Id_Giocatore=pp.Id_Giocatore  where pp.Id_Stagione=2 GROUP BY Nome_Cognome order by sum(pp.Assist) DESC') or die( $db->error );

    echo 
    "<table>";
    echo 
    "<tbody><tr><th>Giocatore</th><th>Assist</th>";
    if (
    $result->num_rows != 0)
              {while(
    $Portieri$result->fetch_assoc()) 
    {

    $Portieri"</tr>
    <tr>
    <td>"
    .$Portieri['Nome_Cognome']."</td>
    <td>"
    .$Portieri['sum(pp.Assist)']."</td>
    </tr>"
    ;
    echo 
    $Portieri;

    }}
    echo 
    "</tbody></table>";


    $result$db->query'SELECT Nome_Cognome, sum(pp.Cart_Gialli) FROM Giocatore g inner join PresenzePartita pp on g.Id_Giocatore=pp.Id_Giocatore  where pp.Id_Stagione=2 GROUP BY Nome_Cognome order by sum(pp.Cart_Gialli) DESC') or die( $db->error );

    echo 
    "<table>";
    echo 
    "<tbody><tr><th>Giocatore</th><th>Cartellini Gialli</th>";
    if (
    $result->num_rows != 0)
              {while(
    $Portieri$result->fetch_assoc()) 
    {

    $Portieri"</tr>
    <tr>
    <td>"
    .$Portieri['Nome_Cognome']."</td>
    <td>"
    .$Portieri['sum(pp.Cart_Gialli)']."</td>
    </tr>"
    ;
    echo 
    $Portieri;

    }}
    echo 
    "</tbody></table>";

    $result$db->query'SELECT Nome_Cognome, sum(pp.Cart_Rossi) FROM Giocatore g inner join PresenzePartita pp on g.Id_Giocatore=pp.Id_Giocatore  where pp.Id_Stagione=2 GROUP BY Nome_Cognome order by sum(pp.Cart_Rossi) DESC') or die( $db->error );

    echo 
    "<table>";
    echo 
    "<tbody><tr><th>Giocatore</th><th>Cartellini Rossi</th>";
    if (
    $result->num_rows != 0)
              {while(
    $Portieri$result->fetch_assoc()) 
    {

    $Portieri"</tr>
    <tr>
    <td>"
    .$Portieri['Nome_Cognome']."</td>
    <td>"
    .$Portieri['sum(pp.Cart_Rossi)']."</td>
    </tr>"
    ;
    echo 
    $Portieri;

    }}
    echo 
    "</tbody></table>";

    $result$db->query'SELECT Nome_Cognome, TRUNCATE(avg(pp.Voto),2) FROM Giocatore g inner join PresenzePartita pp on g.Id_Giocatore=pp.Id_Giocatore  where pp.Id_Stagione=2 GROUP BY Nome_Cognome order by TRUNCATE(avg(pp.Voto),2)  DESC') or die( $db->error );

    echo 
    "<table>";
    echo 
    "<tbody><tr><th>Giocatore</th><th>Media Voto</th>";
    if (
    $result->num_rows != 0)
              {while(
    $Portieri$result->fetch_assoc()) 
    {

    $Portieri"</tr>
    <tr>
    <td>"
    .$Portieri['Nome_Cognome']."</td>
    <td>"
    .$Portieri['TRUNCATE(avg(pp.Voto),2)']."</td>
    </tr>"
    ;
    echo 
    $Portieri;

    }}
    echo 
    "</tbody></table>";

    ?>

    questo è il risultato che viene fuori

    ovvero tutte le tabelle una sotto l'altra.

    Se io invece volessi qualcosa del genere? Ovvero una accanto all'altra?




    come posso fare?

  2. #2
    Dopo la variabile $result, dove stampi le tabelle, modifica il codice in questo modo:
    Codice PHP:
    echo "<table style='float:left'>";
    echo 
    "<tbody><tr><th>Giocatore</th><th>Media Voto</th>";
    if (
    $result->num_rows != 0)
              {while(
    $Portieri$result->fetch_assoc())
    {

    $Portieri"</tr>
    <tr>
    <td>"
    .$Portieri['Nome_Cognome']."</td>
    <td>"
    .$Portieri['TRUNCATE(avg(pp.Voto),2)']."</td>
    </tr>"
    ;
    echo 
    $Portieri;

    }}
    echo 
    "</tbody></table>"

  3. #3
    Utente di HTML.it
    Registrato dal
    Oct 2004
    Messaggi
    138
    grazie

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 © 2025 vBulletin Solutions, Inc. All rights reserved.