2012-02-16 87 views
-1

未定义索引的用于同时从数据库中获取数据到一个数组变量数组的最后一个元件的最后一个元素。我用一个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>"; 
+0

[**在新的代码,请不要使用'mysql_ *'功能**](http://bit.ly/phpmsql)。他们不再被维护[并被正式弃用](https://wiki.php.net/rfc/mysql_deprecation)。看到[**红框**](http://j.mp/Te9zIL)?学习[*准备的语句*](http://j.mp/T9hLWi),并使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli) - [这篇文章](http://j.mp/QEx8IB)将帮助你决定哪个。如果你选择PDO,[这里是一个很好的教程](http://j.mp/PoWehJ)。 – 2013-04-06 10:32:44

回答

0

添加

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

在foreach内,以防止错误

0

你的代码是可怕的。

使用foreach

<font>已被弃用。 $feild_name拼写错误。

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sl。。