Skip to content
Advertisement

How to render specific view after clicking specific button. PHP HTML JS

I am making a page with soccer teams and leauges. Now i`m printing all Leagues that i want from the database.

League 1
League 2
League 3
etc.

As you can see each League has its own League_ID. In Database i also have a table of all teams, and each team has matched League (with League_ID). I also have a view, where i can print table of League that i want. This function in php looks like this.

public function leauge_table(){
    $tables = $this->scoreTableRepository
                    ->getScoreTable(1); 
    //TODO how to change this "1" static to generated
    //TODO when pressing link
    return $this->render('leauge_table', ['table' => $tables]);

And as you can see, when i go to this page i will always see the score table from leauge that has id=1.

And the question is how can i make that when i press for example at “League 2” i will open page but with table matching to League_ID = 2. Shall it be <button></button> or <a></a> in HTML. And how to pass there League_ID so my php back will see which table should render. Thank you really for help.

PS Or maybe do i have to make a seperate view for each leauge score table? And then just simply make buttons direct to these views with simple JS code. But would like to avoid it if it`s possible.

Advertisement

Answer

It can be a link or a button. A link with the league ID as a parameter in the URL is the simplest approach though, if you’re new to the concept. e.g.

<a href="showleague.php?id=1">League 1</a>

The ID would then be available in the php script via $_GET["id], once the link is clicked.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement