2012-05-25 47 views
0

我知道我在這裏做菜鳥錯誤,我需要做一個變量來傳遞 - 雖然我不知道如何處理這個問題,並且搜索在線的tutes也沒有幫助。如果有人能引導我走向正確的方向,我會非常感激。PHP到陣列 - 故障排除

我想將結果回顯到數組中。那是;在$ rss數組中顯示'xml'表中有'xmlurl'行字段。我希望這是有道理的。

// Get URLs from Database 
$result = mysql_query("SELECT * FROM xml"); 
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { 
printf("'%s',", $row["xmlurl"]); 
} 
mysql_free_result($result); 

// Take the URLs (xmlurl) and place them in an array 
$rss = array(
'http://www.xmlurl.com.au', 
'http://www.xmlurl.com.au' 
); 

回答

3

試試這個:

$rss = array(); 

$result = mysql_query("SELECT * FROM xml"); 
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { 
    $rss[] = $row["xmlurl"]; 
} 
mysql_free_result($result); 
+0

謝謝您的答覆。他們非常感謝! – Brandrally

7
$rss = array(); 
while (...) { 
    $rss[] = $row['xmlurl']; 
} 
2
// Get URLs from Database 
$result = mysql_query("SELECT * FROM xml"); 
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { 
    $rss[] = $row["xmlurl"]); 
} 
mysql_free_result($result); 

print_r($rss); // Outputs the $rss array, listing all of the xmlurls'