如何在PHP中循环遍历数组以显示结果

时间:2010-10-14 08:04:30

标签: php

我有一个查询,它从db中检索多个行的两个列。我希望它在使用php的表中显示它,我猜我必须使用二维数组。请帮助我如何继续。

while($row=mysql_fetchrow_array($qry))
{
Please guide how to store the columns in the array[][]


}


[Please guide on how to display the result in the display page]
foreach(   )
{
}

1 个答案:

答案 0 :(得分:0)

// store the columns in the array[][]:
$res = array();
while($row=mysql_fetch_array($qry, MYSQL_NUM)) {
    $res[] = $row;
}

// display the result in the display page
echo "<table>\n";
foreach($res as $row) {
   echo "<tr>\n";
   foreach ($row as $fld) {
      echo "<td>$fld</td>\n";
   }
   echo "</tr>\n";
}
echo "</table>\n";