Jump to content

Not Displaying information


nschmutz

Recommended Posts

I am trying to get the drop down selection to display the results. The user is supposed to choose a start and end year and then after hitting the submit button it is suppose to display the results of the World cup information between the years selected.

I got the drop down menus to be sticky but now I cannot get any results to display. Could someone help to point out how to correct my code to display both the error message and the World Cup results?

 

<html>

 

<head>

 

</head>

 

 

<p>Please enter the start and end years.</p>

 

 

<form action="schmutz_02_03.php" method="post">

 

 

<?php

 

 

 

 

 

$finals1974 = array('West Germany',

'Netherlands',

'2-1',

'West Germany');

 

$finals1978 = array('Argentina',

'Netherlands',

'3-1',

'Argentina');

 

$finals1982 = array('Italy',

'West Germany',

'3-1',

'Argentina');

 

$finals1986 = array('Argentina',

'West Germnay',

'3-2',

'Mexico');

 

$finals1990 = array('West Germany',

'Argentina',

'1-0',

'Italy');

 

$finals1994 = array('Brazil',

'Italy',

'3-2',

'U.S.A.');

 

$finals1998 = array('France',

'Brazil',

'3-0',

'France');

 

$finals2002 = array('Brazil',

'Germany',

'2-0',

'S.Korea.Japan');

 

$finals2006 = array('Italy',

'France',

'5-3',

'Germany');

 

$start = array('1974',

'1978',

'1982',

'1986',

'1990',

'1994',

'1998',

'2002',

'2006');

 

echo 'Start year: <select name="start" value="$start">';

 

 

foreach ($start as $key => $value)

{

if ($key == $_POST['start'])

{

echo "<option value=\"$key\" selected=\"selected\">$value</option>";

}

else

{

echo "<option value=\"$key\">$value</option>";

}

}

 

echo '</select>';

 

$end = array('1974',

'1978',

'1982',

'1986',

'1990',

'1994',

'1998',

'2002',

'2006');

 

echo 'End year: <select name="end" value="$end">';

 

foreach ($end as $key => $value)

{

if ($key == $_POST['end'])

{

 

echo "<option value=\"$key\" selected=\"selected\">$value</option>";

}

else

{

echo "<option value=\"$key\">$value</option>";

}

}

 

echo '</select>';

 

if (isset( $_POST[ 'year' ] ))

{

$yearEnt = $_POST['year'];

//not sure how to include the $finals array into the $years array

 

$years = array ('1974' => $finals1974,

'1978' => $finals1978,

'1982' => $finals1982,

'1986' => $finals1986,

'1990' => $finals1990,

'1994' => $finals1994,

'1998' => $finals1998,

'2002' => $finals2002,

'2006' => $finals2006);

 

$remainder = ($yearEnt - 1974) % 4;

 

 

if(isset($_POST['start']) && isset($_POST['end']))

 

$start = $_POST['start'];

$end = $_POST['end'];

 

 

if($end < $start)

{

echo "End start year should be less than or equal to the end year!</br>";

}

 

for ($i=$_POST['start']; $i <= $_POST['end']; $i = $i + 4)

 

 

foreach ($years as $key=> $value)

{

//echo winner for that year

 

if ($key = $i)

{

echo "The FIFA World Cup champions in $yearEnt were <b>" . $years[$yearEnt][0] . "</b>.\n

They beat <b>" . $years[$yearEnt][1] . "</b>, with a score of <b>" . $years[$yearEnt][2] . "</b>.\n

The finals were hosted by <b>" . $years[$yearEnt][3] . "</b>.</br>";

 

}

}

 

}

 

}

 

 

 

 

echo '<input type="submit" name="submit" value="Go!" />';

 

 

?>

 

</form>

 

</html>

Link to comment
https://forums.phpfreaks.com/topic/205451-not-displaying-information/
Share on other sites

Try this:

<?php
$finals = array();
$finals['1974'] = array('West Germany',
               'Netherlands',
               '2-1',
               'West Germany');
               
$finals['1978'] = array('Argentina',
               'Netherlands',
               '3-1',
               'Argentina');   
            
$finals['1982'] = array('Italy',
               'West Germany',
               '3-1',
               'Argentina');      
            
$finals['1986'] = array('Argentina',
               'West Germnay',
               '3-2',
               'Mexico');
            
$finals['1990'] = array('West Germany',
               'Argentina',
               '1-0',
               'Italy');
            
$finals['1994'] = array('Brazil',
               'Italy',
               '3-2',
               'U.S.A.');

$finals['1998'] = array('France',
               'Brazil',
               '3-0',
               'France');
               
$finals['2002'] = array('Brazil',
               'Germany',
               '2-0',
               'S.Korea.Japan');
               
$finals['2006'] = array('Italy',
               'France',
               '5-3',
               'Germany');

if(isset($_POST['submit']))
{
                          
if(isset($_POST['start']) && isset($_POST['end']))
{ 
	$start = $_POST['start'];
	$end = $_POST['end'];

	if($end < $start)
	{
		$err = "End start year should be less than or equal to the end year!</br>";
	}

	if(!isset($err))
	{
		//Get the selected years and save it into an array
		$years = array();
		$year_count = $start;

		while($year_count <= $end)
		{
			$years[] = $year_count;
			$year_count = $year_count + 4;
		}

		$message ='';
		foreach($years as $value)
		{
			$message .= "The FIFA World Cup champions in $value were <b>" . $finals[$value][0] . "</b>.\n
			They beat <b>" . $finals[$value][1] . "</b>, with a score of <b>" . $finals[$value][2] . "</b>.\n
			The finals were hosted by <b>" . $finals[$value][3] . "</b>.</br>";         
		}
	}
}   
} 
?>
<html>

<head></head>

<body>
<p>Please enter the start and end years.</p>


<form action="" method="post">

<?php        
              
$start = array('1974',
            '1978',
            '1982',
            '1986',
            '1990',
            '1994',
            '1998',
            '2002',
            '2006');   
               
echo 'Start year: <select name="start" value="$start">';

foreach ($start as $value)
{
if ($value == $_POST['start'])
{
	echo "<option value=\"$value\" selected=\"selected\">$value</option>";
}
else
{
	echo "<option value=\"$value\">$value</option>";
}
}

echo '</select>';

$end = array('1974',
            '1978',
            '1982',
            '1986',
            '1990',
            '1994',
            '1998',
            '2002',
            '2006');   
            
echo 'End year: <select name="end" value="$end">';

foreach ($end as $value)
{
if ($value == $_POST['end'])
{
	echo "<option value=\"$value\" selected=\"selected\">$value</option>";
}
else
{
	echo "<option value=\"$value\">$value</option>";
}
}
   
echo '</select>';

echo '<input type="submit" name="submit" value="Go!" />';

?>

</form>
<?php
if(isset($err))
{
echo $err;
}
elseif(isset($message))
{
echo $message;
}
?>
</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.