2010-06-24 120 views
1

我需要获取用户表中的所有用户,然后以数组形式获取结果并遍历它,并为每个用户创建一个XML文件。查询数据库以获取数组

我该怎么做呢?

我猜这个查询应该是类似SELECT * FROM users的东西,但我不确定如何将所有结果作为一个数组来获得,然后如何遍历它们并创建XML。

Thanx提前!

回答

0

这里是一个示例 - //我还没有运行/测试

$result = mysql_query("select * from user"); 

if(mysql_num_rows($result)>0){ 
    while($row = mysql_fetch_array($result)){ 
    $xml_nodes[] = $row;// or you can create XML file for the user of this $row here 
    } 
} 

//this would be double time doing the same thing, if u dont use seperate function to 
// populate $xml_nodes array and return that array 
if(isset($row)){ 
    foreach($xml_nodes as $user_node){ 
    //create XML file for the user of $user_node here 
    } 
} 
相关问题