How to save in a database, confrontations between teams?

Asked

Viewed 117 times

2

I would like to know how to save in a table in the database clashes between teams, for example:

TIME A x TIME B
TIME A x TIME C
TIME B x TIME C
  • 1

    It depends on how your championship system works. You can give more information?

  • I’m still starting, I just wanted an idea of how to save these clashes. because of these clashes I would make a ranking.

  • There is a video lesson explaining a database modeling. This classroom video is on Youtube, https://www.youtube.com/watch?v=2zZQzLAE_HI It will help you a lot.

1 answer

4


An associative table, I believe, would be the most interesting alternative:

CREATE TABLE CONFRONTOS 
(
    ID_CONFRONTO INT PRIMARY KEY,
    ID_TIME_1 INT NOT NULL,
    ID_TIME_2 INT NOT NULL,
    DATA_CONFRONTO DATETIME NOT NULL,
    GOLS_TIME_1 INT NOT NULL,
    GOLS_TIME_2 INT NOT NULL
    -- Aqui você pode colocar FKs, algumas outras coisas de verificação, etc.
)

I made a generic SQL. I don’t know which bank you’re using, but it’s a start.


EDIT

I have no idea which framework you are using, but according to your comment, there is a missing association on Join:

$cons = $fcrud->select('t1.nome, t2.nome, confrontos.gols_time_1, confrontos.gols_time_2', 'confrontos c JOIN times t1 ON t1.id_time = confrontos.id_time_1 JOIN times t2 ON t2.id_time = confrontos.id_time_2', 'ORDER by confrontos.id_confronto DESC',array()); 
$ver = $cons->fetchAll(PDO::FETCH_OBJ); 
  • 2

    Scope creep: 'Oh, but in the future they may invent matches from 3 teams... why not model an Nxn as a link between Confrontations and Times? ', said Joselito, the clueless systems engineer.

  • @gypsy-Morrison-Mendez Thanks for the comment. I did the following, created a simple table with the name TIMES, containing the fields "ID_TIME" and "NAME", then created a table like the one you sent. And my code to relate the field ID_TIME_1 with the field NAME was like this:

  • $cons = $fcrud->select( 'times.name, matches.gols_time_1, matches.gols_time_2', 'clashes JOIN times ON times.id_time = clashes.id_time_1', 'ORDER by confrontations.id_clash DESC',array(); $ver = $cons->fetchAll(PDO::FETCH_OBJ); echo '<pre>'; print_r($ver); echo '</pre>';

  • I cannot relate ID_TIME_2 to the TIMES table NAME field again, I have tried several ways.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.