【问题标题】:Undefined index error for the last element of array [duplicate]数组最后一个元素的未定义索引错误[重复]
【发布时间】:2012-02-16 07:18:36
【问题描述】:

从数据库中获取数据到数组变量中时数组最后一个元素的未定义索引。我使用 for 循环来分隔和 in_array()... 请帮助...

include("includes/global_inc.php");

$qry1=$_REQUEST['qry'];
$feilds2=$_REQUEST['fields1'];
$cnt=$_REQUEST['count'];
$feild_name=explode(",",$feilds2);
$iquery=mysql_query("$qry1") or die(mysql_error());

echo "<table border='1'>";
echo "<tr>";
for($i=0;$i<$cnt;$i++) {
echo "<th>".$feild_name[$i]."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>";

}

echo "</tr>";

for($g=0;$g<$cnt;$g++) {
    while($test=mysql_fetch_array($iquery)) {
        echo "<tr align='center'>";
              echo"<td><font color='black'>".$test[$feild_name[$g]]."</font></td>";
          echo"</tr>";
      }

  }

echo "</table>";

【问题讨论】:

标签: php indexing undefined


【解决方案1】:

添加

If (isset($feild_name[$i])) {

在foreach里面防止错误

【讨论】:

    【解决方案2】:

    你的代码太糟糕了。

    使用foreach

    &lt;font&gt; 已弃用。 $feild_name 拼写错误。

    &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 很草率。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-25
      • 2017-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-14
      • 1970-01-01
      相关资源
      最近更新 更多