Per la mia tesi a scuola sto creando un sito Web PHP che si basa sul sito di Fantasy Football ed è gestito su un server localhost
Sto usando un database MySQL per questo, ma hoproblemi a scoprire come gettare questo database. Ho già un tabel giocatore (id, nome, squadra, posizione), una tabella utente (id, nome, password, id player 1 in squadra, id player 2, id player3, id player4) e una tabella con le partite (id , data, squadra di casa, squadra in trasferta, risultato). Ma voglio aggiungere chi ha segnato in quella partita. Come faccio a farlo perché a volte 2 persone segnano ma possono esserci anche 5 persone che segnano? Come faccio a fare questo?
Tutto l'aiuto è molto apprezzato.
risposte:
2 per risposta № 1Dovrai rappresentare la relazione molti-a-molti con una tabella di collegamento players_who_scored. Questo sarebbe simile a questo:
CREATE TABLE players_who_scored (
player_id INT NOT NULL,
FOREIGN KEY (player_id) REFERENCES players(id),
match_id INT NOT NULL,
FOREIGN KEY (match_id) REFERENCES matches(id),
PRIMARY KEY (player_id,match_id)
);
aggiornare:
se vuoi tenere traccia di tutte le statistiche di un giocatore in una partita, puoi aggiungere le colonne in questo modo:
CREATE TABLE player_stats (
goals INT,
assists INT,
yellow_cards INT,
player_id INT NOT NULL,
FOREIGN KEY (player_id) REFERENCES players(id),
match_id INT NOT NULL,
FOREIGN KEY (match_id) REFERENCES matches(id),
PRIMARY KEY (player_id,match_id)
);