Visualizzazione dei risultati da 1 a 6 su 6
  1. #1

    Mettere in relazione due tabelle

    Ciao a tutti devo mettere in relazione 2 tabelle...potete aiutarmi o spiegarmi con un esempio pratico?
    Codice PHP:
    <?php
    //giocatori
    $team $_SESSION['username'];
    $query "SELECT * FROM GIOC_giovani WHERE squadra = '$team' ORDER BY numero ASC";
    $result mysql_query($query) or die (mysql_error());
    while(
    $row mysql_fetch_array($result)){
    $costo number_format($row['costo'], "0""""."); 

    echo <<<END
    <table>
            <tr>
            <td width="30px">[url="modifica_num.php?id_gioc=
    {$row['id']}"]{$row['numero']}[/url]</td>
            <td width="125px">
    {$row['nome']}</td>
            <td width="125px">
    {$row['cognome']}</td>
            <td width="50px">
    {$row['ruolo']}</td>
            <td width="50px">
    {$row['età']}</td>
            <td width="130px">
    $costo €</td>
            <td width="90px">Salute: 
    {$row['forma_fisica']}</td>
            <td width="90px">Morale: 
    {$row['morale']}</td>
            </tr>
    </table>
    END;
    }
    //portieri
    $query "SELECT * FROM GIOC_giovani_port WHERE squadra = '$team' ORDER BY numero ASC";
    $result mysql_query($query) or die (mysql_error());
    while(
    $row mysql_fetch_array($result)){
    $costo number_format($row['costo'], "0""""."); 
    echo <<<END
    <table>
            <tr>
            <td width="30px">[url="modifica_num_port.php?id_gioc=
    {$row['id']}"]{$row['numero']}[/url]</td>
            <td width="125px">
    {$row['nome']}</td>
            <td width="125px">
    {$row['cognome']}</td>
            <td width="50px">
    {$row['ruolo']}</td>
            <td width="50px">
    {$row['età']}</td>
            <td width="130px">
    $costo €</td>
            <td width="90px">Salute: 
    {$row['forma_fisica']}</td>
            <td width="90px">Morale: 
    {$row['morale']}</td>
            </tr>
    </table>
    END;
    }
    ?>
    Vorrei che i risultati di "SQUADRA_giovani" e "SQUADRA_giovani_port" venissero messi in ordine crescente in base al numero...

  2. #2
    Utente di HTML.it L'avatar di bstefano79
    Registrato dal
    Feb 2004
    Messaggi
    2,520
    non capisco perchè hai 2 tabelle visto che in GIOC_giovani c'è il campo ruolo, insomma secondo me sbagli la struttura del db potresti fare tutto con una tabella

    cmq quello che chiedi lo ottieni così
    Codice PHP:
    <?php 
    //giocatori 
    $team $_SESSION['username']; 
    $query "SELECT * FROM GIOC_giovani,GIOC_giovani_port WHERE squadra = '$team' ORDER BY numero ASC"
    $result mysql_query($query) or die (mysql_error()); 
    while(
    $row mysql_fetch_array($result)){ 
    $costo number_format($row['costo'], "0"""".");  

    echo <<<
    END 
    <table
            <
    tr
            <
    td width="30px">[url="modifica_num.php?id_gioc={$row['id']}"]{$row['numero']}[/url]</td
            <
    td width="125px">{$row['nome']}</td
            <
    td width="125px">{$row['cognome']}</td
            <
    td width="50px">{$row['ruolo']}</td
            <
    td width="50px">{$row['età']}</td
            <
    td width="130px">$costo &#8364;</td> 
            
    <td width="90px">Salute: {$row['forma_fisica']}</td
            <
    td width="90px">Morale: {$row['morale']}</td
            </
    tr
    </
    table
    END

    ?>

  3. #3
    Ciao,grazie per la risposta...uso due tabelle perchè poi ci sono le caratteristiche dei giocatori che si differenziano da quelle dei portieri...cmq avevo provato così:
    Codice PHP:
    <?php
    $team 
    $_SESSION['username'];  
    $query "SELECT * FROM GIOC_giovani AS giov,GIOC_giovani_port AS port  WHERE giov.squadra = '$team' AND port.squadra = '$team' ORDER BY numero ASC";  
    $result mysql_query($query) or die (mysql_error());  
    echo 
    "<table>";
    while(
    $row mysql_fetch_array($result)){  
    $costo number_format($row['costo'], "0"""".");   

    echo <<<END
        <tr>   
            <td width="30px">[url="modifica_num.php?id_gioc=
    {$row['id']}"]{$row['numero']}[/url]</td>   
            <td width="125px">
    {$row['nome']}</td>   
            <td width="125px">
    {$row['cognome']}</td>   
            <td width="50px">
    {$row['ruolo']}</td>   
            <td width="50px">
    {$row['età']}</td>   
            <td width="130px">
    $costo €</td>   
            <td width="90px">Salute: 
    {$row['forma_fisica']}</td>   
            <td width="90px">Morale: 
    {$row['morale']}</td>   
            </tr> 
    END;
    }  
    echo 
    "</table>";
    ?>
    Ma mi restituisce come errore:

    Column 'numero' in where clause is ambiguous

    Ho provato anche la tua soluzione,ma l'errore rimane quasi lo stesso:

    Column 'squadra' in where clause is ambiguous

  4. #4
    Utente di HTML.it L'avatar di bstefano79
    Registrato dal
    Feb 2004
    Messaggi
    2,520
    come al solito ha ragione LUI ;-)


    Prova questa select
    codice:
    SELECT * FROM ( SELECT * FROM GIOC_giovani WHERE squadra = '$team' UNION SELECT * FROM GIOC_giovani_port WHERE squadra = '$team') ORDER BY numero ASC

  5. #5
    ihih sempre

    Grazie per l'altra risposta,ma adesso mi dice:
    Every derived table must have its own alias

  6. #6
    Ho riprovato e finalmente è partito!
    Ecco la query:
    Codice PHP:
    $query "SELECT * FROM GIOC_giovani WHERE squadra = '$team' UNION SELECT * FROM GIOC_giovani_port WHERE squadra = '$team' ORDER BY numero ASC"
    Grazie per l'aiuto!

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.