【发布时间】: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]." </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>";
【问题讨论】:
-
Please, don't use
mysql_*functions in new code。它们不再维护and are officially deprecated。看到red box?改为了解prepared statements,并使用PDO 或MySQLi - this article 将帮助您决定哪个。如果你选择 PDO,here is a good tutorial.