我一直在" Undefined Index" PHP中的错误,我不知道为什么

时间:2017-04-27 23:43:11

标签: php html arrays undefined-index

我一直致力于制定一项计划,该计划在1979年按照欧洲国家的行业记录就业数据,让用户从下拉框中选择一个国家,并按行业显示每个国家的就业百分比。我正在使用PhpStorm 2017.1.1。我一直在使用以下代码为下拉框中的数组提取国家/地区名称:

<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
}
?>

这是我用作参考的嵌套数组:

<?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],
];

问题是我收到错误说&#34;注意:未定义索引:国家&#34;而不是国家本身。

现在,我可以通过更换“国家/地区”来解决这个问题。在带有&#34; 0&#34;的代码中,然后它显示包含国家和行业术语的列。我已经使用了isset(),并且发现我的密钥到目前为止都没有设置,即使根据这样的链接(https://docstore.mik.ua/orelly/webprog/pcook/ch04_03.htm),一切都应该正常工作。

下面是我的一些代码,显示我的显示表(在用户选择国家之后)最终将如何设置:

<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>

答案可能是一个我想念的简单解决方案,但我很累。

如果你们中的任何人能提供帮助,我将非常感激!

0 个答案:

没有答案