开发者

Query database to get back an array

I need to get all of the users in my user table and then get the results as an array and traverse through it and create a XML file for each user.

开发者_JS百科

How would I go about doing that?

I am guessing the query would be something like SELECT * FROM users but I am unsure as to how I can get all the results as an array and then how to traverse through them all one by one and create the XML.

Thanx in advance!


Here is an example- // I havent run/test it

$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
  }
}


Manual page has an example for you: http://www.php.net/manual/en/function.mysql-query.php

All you need is just add $row to array instead of printing it's elements out, with $xmlarr[] = $row; inside of the while loop.

That's all

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜