2012-02-16 85 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。。