PHP到阵列 - 故障排除
问题描述:
I know I am making rookie errors here, and that I need to make a variable to pass forward - though I am not sure how to approach this one, and searching online tutes is not helping. If someone can steer me in the right direction I would be really grateful.
I would like to have the results echo into an array. That is; have 'xmlurl' row field from the 'xml' table display in the $rss array. I hope that makes sense.
// 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'
);
我知道我在这里犯了新手错误,我需要制作一个变量来传递 - 尽管我是 不知道如何处理这个,并搜索在线tutes没有帮助。 如果有人能引导我朝着正确的方向前进,我将非常感激。 p>
我希望将结果回显到数组中。 那是; 在$ rss数组中显示'xml'表中的'xmlurl'行字段。 我希望这是有道理的。 p>
//从Database获取URL
$ result = mysql_query(“SELECT * FROM xml”);
while($ row = mysql_fetch_array($ 结果,MYSQL_ASSOC)){
printf(“'%s',”,$ row [“xmlurl”]);
}
mysql_free_result($ result);
//获取URL(xmlurl)并放置 它们在一个数组
$ rss = array(
'http://www.xmlurl.com.au',
'http://www.xmlurl.com.au'
);
代码> pre>
div>
答
Try this:
$rss = array();
$result = mysql_query("SELECT * FROM xml");
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$rss[] = $row["xmlurl"];
}
mysql_free_result($result);
答
$rss = array();
while (...) {
$rss[] = $row['xmlurl'];
}
答
// 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'