2010-10-14 119 views
-1

我有一个查询,它从db中检索到多行的两列。我想要它在使用php的表格中显示,我必须使用二维数组请帮助我如何继续。的[什么是学习PHP的最好的地方]如何通过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( ) 
{ 
} 
+2

可能重复(http://stackoverflow.com/questions/3793134/what-is-the-best-place-to-learn-php ) – Gordon 2010-10-14 08:08:19

+0

在我以前的答案中的一个小例子:http://stackoverflow.com/questions/3140714/separating-logic-style-in-php-properly/3140805#3140805一个真实的例子,不像下面发布的 – 2010-10-14 08:19:56

+0

有例子在PHP手册中:http://de3.php.net/manual/en/mysqli-result.fetch-assoc.php – Gordon 2011-03-12 13:56:06

回答

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";
+0

你不关闭​​标记。 – 2010-10-14 08:18:31

+0

需求:我刚刚解决了这个问题。 – ash108 2010-10-14 08:35:10

+0

我可以在不使用MSql_NUM的情况下获得解决方案,使用两维数组 – user524707 2010-10-14 08:54:03