I've been working on a program that takes employment data by industry in European countries for 1979, lets the user select a country from a drop down box, and display the employment percents by industry of each country. I'm using PhpStorm 2017.1.1 for this. I've been using the following code to pull country names for the array to use in the drop down box:
<select name = "user1" id = "user1">
<option selected = "selected">Choose an option...</option>
<?php
foreach($EuroJobs as $euroJob) { ?>
<option value = "<?php echo $euroJob['Country']?>"> <?php echo $euroJob['Country'] ?></option>
<?php
}
?>
Here's the nested array I'm using for reference:
<?php
$EuroJobs = [
'Country' => ['Belgium','Denmark','France','W. Germany','Ireland','Italy','Luxembourg','Netherlands','United Kingdom','Austria','Finland','Greece','Norway','Portugal','Spain','Spain','Sweden','Switzerland','Turkey','Bulgaria','Czechoslovakia','E. Germany','Poland','Romania','USSR','Yugoslavia',],
'Agr' => [3.3,9.2,10.8,6.7,23.2,15.9,7.7,6.3,2.7,12.7,13,41.4,9,27.8,22.9,6.1,7.7,66.8,23.6,16.5,4.2,21.7,31.1,34.7,23.7,48.7],
'Min' => [0.9,0.1,0.8,1.3,1,0.6,3.1,0.1,1.4,1.1,0.4,0.6,0.5,0.3,0.8,0.4,0.2,0.7,1.9,2.9,2.9,3.1,2.5,2.1,1.4,1.5],
'Man' => [27.6,21.8,27.5,35.8,20.7,27.6,30.8,22.5,30.2,30.2,25.9,17.6,22.4,24.5,28.5,25.9,37.8,7.9,32.3,35.5,41.2,29.6,25.7,30.1,25.8,16.8],
'PS' =>[0.9,0.6,0.9,0.9,1.3,0.5,0.8,1,1.4,1.4,1.3,0.6,0.8,0.6,0.7,0.8,0.8,0.1,0.6,1.2,1.3,1.9,0.9,0.6,0.6,1.1],
'Con' => [8.2,8.3,8.9,7.3,7.5,10,9.2,9.9,6.9,9,7.4,8.1,8.6,8.4,11.5,7.2,9.5,2.8,7.9,8.7,7.6,8.2,8.4,8.7,9.2,4.9],
'SI' =>[19.1,14.6,16.8,14.4,16.8,18.1,18.5,18,16.9,16.8,14.7,11.5,16.9,13.3,9.7,14.4,17.5,5.2,8,9.2,11.2,9.4,7.5,5.9,6.1,6.4],
'Fin' => [6.2,6.5,6,5,2.8,1.6,4.6,6.8,5.7,4.9,5.5,2.4,4.7,2.7,8.5,6,5.3,1.1,0.7,0.9,1.2,0.9,0.9,1.3,0.5,11.3],
'SPS' => [26.6,32.2,22.6,22.3,20.8,20.1,19.2,28.5,28.3,16.8,24.3,11,27.6,16.7,11.8,32.4,15.4,11.9,18.2,17.9,22.1,17.2,16.1,11.7,23.6,5.3],
'TC' => [7.2,7.1,5.7,6.1,6.1,5.7,6.2,6.8,6.4,7,7.6,6.7,9.4,5.7,5.5,6.8,5.7,3.2,6.7,7,8.4,8,6.9,5,9.3,4],
];
The issue is that I get an error saying "Notice: Undefined Index: Country" instead of the countries themselves.
Now, I can fix this by replacing the 'Country' in the code with a "0", but then it displays the column with the Country and industry terms. I've used isset()
, and discovered that none of my keys are set up so far apparently, even though according to links like this (https://docstore.mik.ua/orelly/webprog/pcook/ch04_03.htm), everything should work just fine.
Below is a bit of my code showing how my display table (after the user picks a country) will ultimately be set up:
<table>
<tr>
<th>Country</th>
<th>Agriculture (%)</th>
<th>Mining (%)</th>
<th>Manufacturing (%)</th>
<th>Power (%)</th>
<th>Construction (%)</th>
<th>Services (%)</th>
<th>Finance (%)</th>
<th>Social and Personal (%)</th>
<th>Transport and Comm. (%)</th>
</tr>
<tr>
<td><?php echo $_POST["Country"][0]; ?></td>
<td><?php echo $_POST["Agr"][1]; ?></td>
The answer is probably a simple solution I'm missing, but I'm very tired.
If any of you can help, I would really appreciate it!