Hi Dzordz,
There are lots of different ways to achieve the sort of thing you are looking to do.
It's probably easier to just show you a way than try to explain. The following could be adapted, of course, ...
<?php
// Find out whether a league has been selected
$SELECTED_LEAGUE = isset($_REQUEST['league'])? $_REQUEST['league']: -1;
$SELECTED_TEAM = isset($_REQUEST['team'])? $_REQUEST['team']: -1;
?>
<html>
<head>
<title></title>
</head>
<body>
<!-- No need to use post ... can complicate the user's experience -->
<form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<select name="league">
<?php
//creates the drowpdown menu for selection of the league
$leagues = file('leagues.dat');
$count_leagues = count($leagues);
for($i = 0; $i < $count_leagues; $i++){
// Must trim each entry of carriage returns and other whitespace
$leagues[$i] = trim($leagues[$i]);
// Decide whether this option is selected
$selected = ($i == $SELECTED_LEAGUE)? ' selected': '';
echo '<option value="'.$i.'"'.$selected.'>'.$leagues[$i].'</option>';
}
?>
</select>
<input type="submit" value="Select">
</form>
<?php
// Now, only show the second form if a selection
// has been made on the first form
if($SELECTED_LEAGUE == -1){
?>
<p>Choose a league!</p>
<?php
} else {
$league_title = $leagues[$SELECTED_LEAGUE];
?>
<hr>
<h1><?php echo $league_title; ?></h1>
<form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="hidden" name="league" value="<?php echo $SELECTED_LEAGUE; ?>">
<select name="team">
<?php
$teams = file(strtolower($league_title).'.dat');
$count_teams = count($teams);
for ($i = 0; $i < $count_teams; $i++){
// Must trim each entry of carriage returns and other whitespace
$teams[$i] = trim($teams[$i]);
// Decide whether this option is selected
$selected = ($i == $SELECTED_TEAM)? ' selected': '';
echo '<option value="'.$i.'"'.$selected.'>'.$teams[$i].'</option>';
}
?>
</select>
<input type="submit" value="Submit">
</form>
<?php
if($SELECTED_TEAM == -1){
?>
<p>Choose a team!</p>
<?php
} else {
$team_title = $teams[$SELECTED_TEAM];
?>
<hr><h2><?php echo $team_title; ?></h2>
<?php
}
}
?>
</body>
</html>
Note that in order for me to test it, I used the data files in the attached zip (English leagues).
Come back if you don't understand anything.
Paul 🙂