NaniG Posted September 28, 2011 Share Posted September 28, 2011 Hi to all, Here is my code to out put the and saved in xml file... <?php ob_start(); $conn=mysql_connect("localhost","root",""); $mysql_select_db("test",$conn); $selqry=mysql_query("select * from table_name"); $doc = new DomDocument('1.0'); $root = $doc->createElement('userlist'); $root = $doc->appendChild($root); while($row = mysql_fetch_assoc($selqry)) { $users= $doc->createElement('users'); $users= $root->appendChild($users); foreach($row as $fieldname => $fieldvalue) { $child = $doc->createElement($fieldname); $child = $calls->appendChild($child); $value = $doc->createTextNode($fieldvalue); $value = $child->appendChild($value); } } echo 'Wrote: ' . $doc->save("userslist.xml") . ' bytes'; ?> the values are stored in xml format as <userlist> <users> <date>2011-09-27 22:47:55</date> <channel>abc/3024-b5f96be8</channel> <name>Test</name> <email>[email protected]</email> </users> </userlist> But i wanted to store blow mentioned as it is... <userlist> <users> <date>2011-09-27 22:47:55</date> <channel>3024</channel> <name>Test</name> <email>[email protected]</email> </users> </userlist> Please help me out....! Thanks and Regards.... Quote Link to comment https://forums.phpfreaks.com/topic/248062-xml-php-and-mysql/ Share on other sites More sharing options...
requinix Posted September 28, 2011 Share Posted September 28, 2011 And 3024 is what, exactly? Can you write a SQL query to show the details you want? Do that, then substitute it into your code. Quote Link to comment https://forums.phpfreaks.com/topic/248062-xml-php-and-mysql/#findComment-1273733 Share on other sites More sharing options...
xyph Posted September 28, 2011 Share Posted September 28, 2011 He wants to extract 3024 out of abc/3024-b5f96be8 String functions if the data is as simple as your example. RegEx if it's not. <?php $fieldname = 'channel'; $fieldvalue = 'abc/3024-b5f96be8'; if( $fieldname == 'channel' ) { $slashPos = strpos( $fieldvalue,'/' ) + 1; $fieldvalue = substr( $fieldvalue, $slashPos, strpos( $fieldvalue,'-') - $slashPos ); } echo $fieldvalue; ?> Quote Link to comment https://forums.phpfreaks.com/topic/248062-xml-php-and-mysql/#findComment-1273743 Share on other sites More sharing options...
NaniG Posted September 29, 2011 Author Share Posted September 29, 2011 Thanx xyph... Solved my problem... and am having another issue... depending upon the fieldvalue, i have to create a new attribute (which is not in the DB fields). suppose if the fieldvalue is 3024, then i have to add new own child-attribute. ie input or output and the out put would be like these.... <userlist> <users> <date>2011-09-27 22:47:55</date> <channel>3024</channel> <name>Test</name> <email>[email protected]</email> <io>I</io>----------------------------------------------------------- (Own child attribute) </users> </userlist> thanks in advance... Quote Link to comment https://forums.phpfreaks.com/topic/248062-xml-php-and-mysql/#findComment-1274010 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.