2010-10-14 72 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